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]

[RFA] PR c++/41785


Hello,

The bottom line in this PR is that we do not handle ARGUMENT_PACK_SELECT nodes
when we do template arguments comparison. This causes some template
specialization lookups to fail when they shouldn't.

A somewhat detailed analysis of the PR is available at
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41785

The attached patch has been tested against trunk on x86_64-unknown-linux-gnu.

commit 5f1befc55dbe8f0d383880ed19bf292a81fa6952
Author: Dodji Seketeli <dodji@redhat.com>
Date:   Mon Oct 26 16:47:11 2009 +0100

    Fix PR c++/41785
    
    gcc/cp/ChangeLog:
    
    	PR c++/41785
    	* pt.c (template_args_equal): Handle comparison of
    	an ARGUMENT_PACK_SELECT node with the arguments node it selects into.
    	* cp-tree.def: Fix a typo in the description of TYPE_PACK_EXPANSION.
    
    gcc/testsuite/ChangeLog:
    	PR c++/41785
    	* gcc/testsuite/g++.dg/cpp0x/variadic96.C: New test.

diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def
index 4df01a8..28ecc5b 100644
--- a/gcc/cp/cp-tree.def
+++ b/gcc/cp/cp-tree.def
@@ -393,7 +393,7 @@ DEFTREECODE (NONTYPE_ARGUMENT_PACK, "nontype_argument_pack", tcc_expression, 1)
      };
 
    The derivation from tuple contains a TYPE_PACK_EXPANSION for the
-   template arguments. Its EXPR_PACK_EXPANSION is "Values&" and its
+   template arguments. Its PACK_EXPANSION_PATTERN is "Values&" and its
    PACK_EXPANSION_PARAMETER_PACKS will contain "Values".  */
 DEFTREECODE (TYPE_PACK_EXPANSION, "type_pack_expansion", tcc_type, 0)
 
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 084ad1c..e80bc30 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -5818,6 +5818,18 @@ template_args_equal (tree ot, tree nt)
 	  return 0;
       return 1;
     }
+  else if (ot && TREE_CODE (ot) == ARGUMENT_PACK_SELECT)
+    {
+      /* We get here probably because we are in the middle of substituting
+         into the pattern of a pack expansion. In that case the
+	 ARGUMENT_PACK_SELECT temporarily replaces the pack argument we are
+	 interested in. So we want to use the initial pack argument for
+	 the comparison.  */
+      ot = ARGUMENT_PACK_SELECT_FROM_PACK (ot);
+      if (nt && TREE_CODE (nt) == ARGUMENT_PACK_SELECT)
+	nt = ARGUMENT_PACK_SELECT_FROM_PACK (nt);
+      return template_args_equal (ot, nt);
+    }
   else if (TYPE_P (nt))
     return TYPE_P (ot) && same_type_p (ot, nt);
   else if (TREE_CODE (ot) == TREE_VEC || TYPE_P (ot))
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic96.C b/gcc/testsuite/g++.dg/cpp0x/variadic96.C
new file mode 100644
index 0000000..d4709d0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/variadic96.C
@@ -0,0 +1,26 @@
+// Contributed by Dodji Seketeli <dodji@redhat.com>
+// Origin: PR c++/41785
+// { dg-options -std=c++0x }
+
+struct a {};
+
+template < typename T, typename ENCLOSING >
+struct base;
+
+template < typename... T >
+struct derived
+  : public base< T, derived< T... > >...
+{};
+
+template < typename... T>
+struct base< a, derived< T... > >
+{
+  typedef derived< T... >
+          Derived;
+};
+
+int main()
+{
+  derived< a > instance;
+}
+

-- 
Dodji Seketeli
Red Hat


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