http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49458
Summary: [C++0x] Obvious candidate for conversion to function lvalue rejected Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: hst...@ca.ibm.com CC: micha...@ca.ibm.com Host: powerpc64-unknown-linux-gnu Target: powerpc64-unknown-linux-gnu According to the 2011 FCD, subclause 13.3.1.6 [over.match.ref] paragraph 1: >>> The conversion functions of S and its base classes are considered, except that for copy-initialization, only the non-explicit conversion functions are considered. Those that are not hidden within S and yield type "lvalue reference to cv2 T2" (when 8.5.3 requires an lvalue result) or "cv2 T2" or "rvalue reference to cv2 T2" (when 8.5.3 requires an rvalue result), where "cv1 T" is reference-compatible (8.5.3) with "cv2 T2", are candidate functions. <<< Both lvalue references and rvalue references to function types require binding to function lvalues. The following test case is expected to compile clean. GCC still does not compile if #1 is commented out. GCC will compile if #2 is commented out, but that behaviour is unsupported by the referenced wording. In particular, #2 should be a candidate and (from the wording) #1 is not for conversion to a function lvalue. ### Self-contained source (a.cpp):> cat a.cpp typedef void ftype(); void foo() { } struct A { operator ftype&&(void); // #1 operator ftype&(void) { return foo; } // #2 }; ftype &&frvref = A(); ### Compiler invocation: g++-4.6.0 -std=c++0x -o a.o -c a.cpp ### Compiler output: a.cpp:9:20: error: invalid initialization of reference of type ‘void (&&)()’ from expression of type ‘A’ ### g++ -v output:> g++-4.6.0 -v Using built-in specs. COLLECT_GCC=g++-4.6.0 COLLECT_LTO_WRAPPER=/data/gcc/libexec/gcc/powerpc64-unknown-linux-gnu/4.6.0/lto-wrapper Target: powerpc64-unknown-linux-gnu Configured with: ./configure --prefix=/data/gcc --program-suffix=-4.6.0 --disable-libssp --disable-libgcj --enable-version-specific-runtime-libs --with-cpu=default32 --enable-secureplt --with-long-double-128 --enable-shared --enable-__cxa_atexit --enable-threads=posix --enable-languages=c,c++,fortran --with-gmp=/usr/local Thread model: posix gcc version 4.6.0 (GCC)