C++ PATCH for c++/81843, ICE with member variadic template

Message ID CADzB+2n8SsWEwpdhztiaZc+ZJwcN=W+Nqg=TRJ3-O6twkHkvaA@mail.gmail.com
State New
Headers show
Series
  • C++ PATCH for c++/81843, ICE with member variadic template
Related show

Commit Message

Jason Merrill Jan. 17, 2018, 5:41 p.m.
My patch for 72801 added in enclosing template arguments, but then as
a result we wrongly tried to deduce them.

Tested x86_64-pc-linux-gnu, applying to trunk and 7.
commit 7b299d41c412665a03c5bcdb088d3a39dc86d9c2
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Jan 17 11:12:23 2018 -0500

            PR c++/81843 - ICE with variadic member template.
    
            PR c++/72801
            * pt.c (unify_pack_expansion): Don't try to deduce enclosing
            template args.

Patch

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 322408d92ec..1c7b91ac0df 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -20356,6 +20356,7 @@  unify_pack_expansion (tree tparms, tree targs, tree packed_parms,
 
   /* Add in any args remembered from an earlier partial instantiation.  */
   targs = add_to_template_args (PACK_EXPANSION_EXTRA_ARGS (parm), targs);
+  int levels = TMPL_ARGS_DEPTH (targs);
 
   packed_args = expand_template_argument_pack (packed_args);
 
@@ -20371,6 +20372,8 @@  unify_pack_expansion (tree tparms, tree targs, tree packed_parms,
 
       /* Determine the index and level of this parameter pack.  */
       template_parm_level_and_index (parm_pack, &level, &idx);
+      if (level < levels)
+	continue;
 
       /* Keep track of the parameter packs and their corresponding
          argument packs.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic171.C b/gcc/testsuite/g++.dg/cpp0x/variadic171.C
new file mode 100644
index 00000000000..1e268141d6d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/variadic171.C
@@ -0,0 +1,12 @@ 
+// PR c++/81843
+// { dg-do compile { target c++11 } }
+
+template < typename > struct A;
+template < typename, typename > struct B;
+template < typename ... S > struct C
+{
+  template < typename > struct D {};
+  template < typename ... T > struct D < A < B < S, T > ... > >;
+};
+
+C <>::D < A < B < int, int > > > c;