Gcc 4.3.0 diagnoses the line marked "<<< error? <<<" in the program below. I'd like to believe the program is well-formed and that the compiler should be able to correctly deduce the template arguments from the initialed expression without explicitly providing the template argument list. template <class T> void f (T) { } template <class T> void g (T&) { } template <class T> void h (T&&) { } int main () { { void (*pf)(int) = &f; } // okay { void (*pf)(int&) = &f; } // okay { void (*pf)(int&&) = &f; } // okay { void (*pf)(int&) = &g; } // okay { void (*pf)(int&&) = &h; } // okay { void (*pf)(int&) = &h; } // <<< error? <<< { void (*pf)(int&) = &h<int&>; } // okay // { void (*pf)(int&&) = &h<int&>; } // error! // { void (*pf)(int&&&) = &h<int&>; } // error! } t.cpp: In function ‘int main()’: t.cpp:14: error: no matches converting function ‘h’ to type ‘void (*)(int&)’ t.cpp:3: error: candidates are: template<class T> void h(T&&)
This is core issue 873, http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#873
Subject: Bug 36816 Author: jason Date: Thu Oct 8 16:09:31 2009 New Revision: 152565 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=152565 Log: PR c++/36816 * pt.c (maybe_adjust_types_for_deduction): Do rvalue ref adjustment even when DEDUCE_EXACT. Added: trunk/gcc/testsuite/g++.dg/cpp0x/rv-deduce.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/pt.c trunk/gcc/testsuite/ChangeLog
Fixed for 4.5.