http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49389
Summary: [C++0x] Wrong value category for pointer-to-member expression with rvalue object expression Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: daniel.krueg...@googlemail.com CC: ja...@redhat.com gcc 4.7.0 20110611 (experimental) in C++0x mode rejects the following program at the line marked with #: //---- template<class T> T&& val(); struct A {}; typedef decltype(val<A>().*val<int A::*>()) type; template<class> struct assert_type; template<> struct assert_type<int&&> {}; assert_type<type> test; // # //---- "error: aggregate 'assert_type<int&> test' has incomplete type and cannot be defined" Further testing reveals that the deduced type is 'int&' instead of 'int&&'. According to my reading of 5.5 [expr.mptr.oper] p6: "The result of a .* expression whose second operand is a pointer to a data member is of the same value category (3.10) as its first operand." we have an xvalue expression val<A>() as the first operand, which should result in an xvalue expression category for the complete pointer-to-member expression. Referring to 7.1.6.2 [dcl.type.simple] p4, we should fall into bullet 2: "otherwise, if e is an xvalue, decltype(e) is T&&, where T is the type of e;" which should have the effect of returning int&&, not int&. Therefore gcc should accept this program.