[Bug c++/57063] Valid static_cast from data member to rvalue reference fails to compile
tsoae at mail dot ru
gcc-bugzilla@gcc.gnu.org
Thu Apr 25 13:51:00 GMT 2013
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_cast<T &&>(value))>{});
PRINT_VALUE(std::is_rvalue_reference<
decltype(static_cast<T &&>(value))>{});
std::cout << std::endl;
}
T &&value;
};
struct A {};
int main()
{
X<int>{0}.f();
X<A>{A()}.f();
}
When T = int, static_cast<T &&>(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.
More information about the Gcc-bugs
mailing list