]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: argument pack with expansion [PR86355]
authorJason Merrill <jason@redhat.com>
Wed, 26 May 2021 21:38:42 +0000 (17:38 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 27 May 2021 17:41:18 +0000 (13:41 -0400)
This testcase revealed that we were using PACK_EXPANSION_EXTRA_ARGS a lot
more than necessary; use_pack_expansion_extra_args_p meant to use it in the
case of corresponding arguments in different argument packs differing in
whether they are pack expansions, but it was mistakenly also returning true
for the case of a single argument pack containing both expansion and
non-expansion elements.

Surprisingly, just disabling that didn't lead to any regressions in the
testsuite; it seems other changes have prevented us getting to this point
for code that used to exercise it.  So this patch limits the check to
arguments in the same position in the packs, and asserts that we never
actually see a mismatch.

PR c++/86355

gcc/cp/ChangeLog:

* pt.c (use_pack_expansion_extra_args_p): Don't compare
args from the same argument pack.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/alias-decl-variadic2.C: New test.

gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic2.C [new file with mode: 0644]

index e4950aa448a575549ebb7be9a5e9609b5437038c..bb22d685617e2bc61b64ca2d35cf76afafc0dcd0 100644 (file)
@@ -12422,9 +12422,9 @@ use_pack_expansion_extra_args_p (tree parm_packs,
       return false;
     }
 
-  bool has_expansion_arg = false;
   for (int i = 0 ; i < arg_pack_len; ++i)
     {
+      bool has_expansion_arg = false;
       bool has_non_expansion_arg = false;
       for (tree parm_pack = parm_packs;
           parm_pack;
@@ -12444,7 +12444,10 @@ use_pack_expansion_extra_args_p (tree parm_packs,
        }
 
       if (has_expansion_arg && has_non_expansion_arg)
-       return true;
+       {
+         gcc_checking_assert (false);
+         return true;
+       }
     }
   return false;
 }
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic2.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic2.C
new file mode 100644 (file)
index 0000000..4299c7e
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/86355
+// { dg-do compile { target c++11 } }
+
+template <int...> struct integral_constant {
+  static const int value = 1;
+};
+template <class... T> using mp_all = integral_constant<T::value...>;
+template <class... T> using check2 = mp_all<mp_all<T..., integral_constant<0>>>;
+check2<> x;
+
+template <class T, class U> struct assert_same;
+template <class T> struct assert_same<T,T> { };
+assert_same<decltype(x),integral_constant<1>> a;