[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 tsoae at mail dot ru 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 string template class T struct X { T f() { return static_castT (value); } T value; }; enum E {}; template class Xint; template class XE; template class Xstd::string; template class Xint(); template class Xint[1]; test.cpp: In instantiation of ‘T XT::f() [with T = int]’: test.cpp:15:20: required from here test.cpp:8:43: error: cannot bind ‘int’ lvalue to ‘int’ return static_castT (value); ^ test.cpp: In instantiation of ‘T XT::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 XT::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 --- Comment #3 from Paolo Carlini paolo.carlini at oracle dot com 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 #4 from Nikolka tsoae at mail dot ru 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 iostream #include type_traits #define PRINT_VALUE(...) \ std::cout #__VA_ARGS__ = __VA_ARGS__ std::endl template class T struct X { void f() { PRINT_VALUE(std::is_lvalue_reference decltype(static_castT (value)){}); PRINT_VALUE(std::is_rvalue_reference decltype(static_castT (value)){}); std::cout std::endl; } T value; }; struct A {}; int main() { Xint{0}.f(); XA{A()}.f(); } When T = int, static_castT (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 Paolo Carlini paolo.carlini at oracle dot com changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2013-04-24 Ever Confirmed|0 |1 --- Comment #1 from Paolo Carlini paolo.carlini at oracle dot com 2013-04-24 21:44:16 UTC --- The alias declaration doesn't play a role: struct X { int f() { return static_castint(value); } int value; };