https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125651

            Bug ID: 125651
           Summary: std::move with const char*&&ptr causes an error
           Product: gcc
           Version: 16.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: levo.delellis at gmail dot com
  Target Milestone: ---

I'm certain this is a bug. In clang++ this compiles fine. I don't think it's an
issue with the header because I was able to reproduce it using my own move
function (which clang also accepts)

error: binding reference of type ‘const char*&&’ to
‘std::remove_reference<char*>::type’ {aka ‘char*’} discards qualifiers

#include <utility>

void test(const char*&&ptr) { }

int main() {
        test(new char); // ok
        test(std::move(new char)); // err in gcc
        char*p = new char;
        test(std::move(p)); // err in gcc
}

Calling these move works in clang

template <typename T> T&& move(T&& t) { return static_cast<T&&>(t); }
template <typename T> T&& move(T&  t) { return static_cast<T&&>(t); }

Reply via email to