This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Committed: fix rvalue reference deduction with variadic templates (PR c++/33939)


PR c++/33939 is a problem with the interaction between variadic
templates and rvalue references. The problem itself goes back to the
merge of the rvalue references code, which didn't get fully updated
when some of the type-unification bits in the mainline compiler were
changed. The archeology gets more interesting, because this problem
doesn't come up in ConceptGCC, where we had the test-cases to expose
the problem... the testcase didn't come over when rvalue references
and variadic templates entered the 4.3 mainline separately.

Anyway, I've committed this obvious little patch that brings
unify_pack_expansion in sync with type_unification_real. Tested
i686-pc-linux-gnu.

  - Doug

2007-11-05  Douglas Gregor  <doug.gregor@gmail.com>

	PR c++/33939
	* pt.c (unify_pack_expansion): bring handling of function call
	arguments into line with type_unification_real.

2007-11-05  Douglas Gregor  <doug.gregor@gmail.com>

	PR c++/33939
	* g++.dg/cpp0x/variadic-rref.C: New.
Index: testsuite/g++.dg/cpp0x/variadic-rref.C
===================================================================
--- testsuite/g++.dg/cpp0x/variadic-rref.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/variadic-rref.C	(revision 0)
@@ -0,0 +1,36 @@
+// { dg-options "-std=c++0x" }
+// PR c++/33939
+template<typename T>
+struct refs_only;
+
+template<typename T>
+struct refs_only<T &>
+{};
+
+template<typename T>
+refs_only<T> foo( T && t)
+{
+    return refs_only<T>();
+}
+
+template<typename... T>
+struct va_refs_only;
+
+template<typename T>
+struct va_refs_only<T>
+  : refs_only<T>
+{};
+
+template<typename... T>
+va_refs_only<T...> bar( T &&... t)
+{
+    return va_refs_only<T...>();
+}
+
+int main()
+{
+    int j = 0;
+    foo(j);
+    bar(j); // error: invalid use of incomplete type 'struct refs_only<int>'
+}
+
Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 129899)
+++ cp/pt.c	(working copy)
@@ -12280,6 +12280,7 @@ unify_pack_expansion (tree tparms, tree 
       /* Unify the pattern with the current argument.  */
       {
         tree arg = TREE_VEC_ELT (packed_args, i);
+	tree arg_expr = NULL_TREE;
         int arg_strict = strict;
         bool skip_arg_p = false;
 
@@ -12330,7 +12331,8 @@ unify_pack_expansion (tree tparms, tree 
 
                 if (!skip_arg_p)
                   {
-                    arg = TREE_TYPE (arg);
+		    arg_expr = arg;
+                    arg = unlowered_expr_type (arg);
                     if (arg == error_mark_node)
                       return 1;
                   }
@@ -12340,7 +12342,8 @@ unify_pack_expansion (tree tparms, tree 
 
             if (!subr)
               arg_strict |= 
-                maybe_adjust_types_for_deduction (strict, &parm, &arg, NULL);
+                maybe_adjust_types_for_deduction (strict, &parm, &arg, 
+						  arg_expr);
           }
 
         if (!skip_arg_p)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]