[Bug c++/57063] Valid static_cast from data member to rvalue reference fails to compile
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57063 --- Comment #4 from Nikolka 2013-04-25 13:51:21 UTC --- It looks like the root of the issue is that static_cast produces an expression with wrong value category sometimes. #include #include #define PRINT_VALUE(...) \ std::cout << #__VA_ARGS__ " = " << __VA_ARGS__ << std::endl template struct X { void f() { PRINT_VALUE(std::is_lvalue_reference< decltype(static_cast(value))>{}); PRINT_VALUE(std::is_rvalue_reference< decltype(static_cast(value))>{}); std::cout << std::endl; } T &&value; }; struct A {}; int main() { X{0}.f(); X{A()}.f(); } When T = int, static_cast(value) is wrongfully treated as an lvalue. In the first example the compiler thinks that we want to return lvalue of type int by rvalue reference int &&, which would be invalid.
[Bug c++/57063] Valid static_cast from data member to rvalue reference fails to compile
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57063 --- Comment #3 from Paolo Carlini 2013-04-25 08:34:30 UTC --- In general, testcases must be minimal, otherwise, eg, you start wondering (as I did) whether the bug is in the code handling alias declarations.
[Bug c++/57063] Valid static_cast from data member to rvalue reference fails to compile
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57063 --- Comment #2 from Nikolka 2013-04-25 07:19:20 UTC --- The alias is added for convenience - we can quickly test handling of different types so. It seems that there is no problem with class types and function types, the error arises when T is a scalar type or an array type: #include template struct X { T &&f() { return static_cast(value); } T &&value; }; enum E {}; template class X; template class X; template class X; template class X; template class X; test.cpp: In instantiation of ‘T&& X::f() [with T = int]’: test.cpp:15:20: required from here test.cpp:8:43: error: cannot bind ‘int’ lvalue to ‘int&&’ return static_cast(value); ^ test.cpp: In instantiation of ‘T&& X::f() [with T = E]’: test.cpp:16:20: required from here test.cpp:8:43: error: cannot bind ‘E’ lvalue to ‘E&&’ test.cpp: In instantiation of ‘T&& X::f() [with T = int [1]]’: test.cpp:19:20: required from here test.cpp:8:43: error: cannot bind ‘int [1]’ lvalue to ‘int (&&)[1]’
[Bug c++/57063] Valid static_cast from data member to rvalue reference fails to compile
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57063 Paolo Carlini changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2013-04-24 Ever Confirmed|0 |1 --- Comment #1 from Paolo Carlini 2013-04-24 21:44:16 UTC --- The alias declaration doesn't play a role: struct X { int&& f() { return static_cast(value); } int&& value; };