Bug 36816 - [c++0x] error deducing template argument taking the address of rvalue reference template
Summary: [c++0x] error deducing template argument taking the address of rvalue referen...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-12 22:35 UTC by Martin Sebor
Modified: 2009-10-08 17:48 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-10-07 21:27:37


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2008-07-12 22:35:49 UTC
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&&)
Comment 1 Jason Merrill 2009-10-07 21:27:37 UTC
This is core issue 873, http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#873
Comment 2 Jason Merrill 2009-10-08 16:09:55 UTC
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

Comment 3 Jason Merrill 2009-10-08 17:48:08 UTC
Fixed for 4.5.