Patchwork C++ PATCH for c++/48313 (T&& deduction from function arg)

login
register
mail settings
Submitter Jason Merrill
Date March 29, 2011, 12:08 a.m.
Message ID <4D9122F1.1070402@redhat.com>
Download mbox | patch
Permalink /patch/88705/
State New
Headers show

Comments

Jason Merrill - March 29, 2011, 12:08 a.m.
We were deducing the wrong template argument when passing a function 
template-id to a T&& parameter, because the code for resolving an 
overloaded function based on a parameter type wasn't passing in an 
argument expression to maybe_adjust_parameter_types_for_deduction.  The 
easy fix was to check the type, as functions are always lvalues.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit e87037b708e895527437491e5c1f751ccd2b649a
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Mar 28 16:40:55 2011 -0400

    	PR c++/48313
    	* pt.c (maybe_adjust_types_for_deduction): Handle T&& deduction
    	from overloaded function.

Patch

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 9032dd9..dfc726a 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -13936,7 +13936,10 @@  maybe_adjust_types_for_deduction (unification_kind_t strict,
       && TYPE_REF_IS_RVALUE (*parm)
       && TREE_CODE (TREE_TYPE (*parm)) == TEMPLATE_TYPE_PARM
       && cp_type_quals (TREE_TYPE (*parm)) == TYPE_UNQUALIFIED
-      && arg_expr && real_lvalue_p (arg_expr))
+      && (arg_expr ? real_lvalue_p (arg_expr)
+	  /* try_one_overload doesn't provide an arg_expr, but
+	     functions are always lvalues.  */
+	  : TREE_CODE (*arg) == FUNCTION_TYPE))
     *arg = build_reference_type (*arg);
 
   /* [temp.deduct.call]
diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-deduce2.C b/gcc/testsuite/g++.dg/cpp0x/rv-deduce2.C
new file mode 100644
index 0000000..160296f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/rv-deduce2.C
@@ -0,0 +1,18 @@ 
+// PR c++/48313
+// { dg-options -std=c++0x }
+
+template<typename F>
+void f(F&&) { }
+
+void g() { }
+
+template<typename T> void h() { }
+
+int main()
+{
+  f( g );       // OK
+  void (&p)() = h<int>;
+  f( p );       // OK
+  f( h<int> );  // ???
+}
+