On 3/18/25 8:49 AM, Marek Polacek wrote:
On Mon, Mar 17, 2025 at 10:30:45PM -0400, Patrick Palka wrote:
On Mon, 17 Mar 2025, Marek Polacek wrote:

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/14/13?

-- >8 --
r12-1094 mentions that adding the assert didn't lead to any regressions
in the testsuite, but this test case demonstrates that we can reach it
with valid code.

Here we arrive in use_pack_expansion_extra_args_p with t which is an
expansion whose pattern is void(Ts, Us) and tparm packs are {Us, Ts},
and parm_packs is { Ts -> <int, int>, Us -> <A, P...> }.  We want to
expand the pack into void(int, A) and void(int, P...).  We compare
int to A, which is fine, but then int to P... which crashes.  But
the code is valid so this patch removes the assert.

        PR c++/118104

gcc/cp/ChangeLog:

        * pt.cc (use_pack_expansion_extra_args_p): Remove an assert.

gcc/testsuite/ChangeLog:

        * g++.dg/cpp0x/alias-decl-variadic3.C: New test.
        * g++.dg/cpp0x/alias-decl-variadic4.C: New test.
---
  gcc/cp/pt.cc                                      | 11 ++++++++++-
  gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic3.C | 13 +++++++++++++
  gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic4.C | 11 +++++++++++
  3 files changed, 34 insertions(+), 1 deletion(-)
  create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic3.C
  create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic4.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 8aaae446868..35c68a6e3f2 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -13180,7 +13180,16 @@ use_pack_expansion_extra_args_p (tree t,
if (has_expansion_arg && has_non_expansion_arg)
        {
-         gcc_checking_assert (false);
+         /* We can get here with:
+
+             template <class... Ts> struct X {
+               template <class... Us> using Y = Z<void(Ts, Us)...>;
+             };
+             template <class A, class... P>
+             using foo = X<int, int>::Y<A, P...>;
+
+            where we compare int and A and then the second int and P...,
+            whose expansion-ness doesn't match, but that's OK.  */
          return true;
        }
      }
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic3.C 
b/gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic3.C
new file mode 100644
index 00000000000..abac9d8b4c0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic3.C
@@ -0,0 +1,13 @@
+// PR c++/118104
+// { dg-do compile { target c++11 } }
+
+template <class... Ts> struct X {
+  template <class... Us> using Y = X<void(Ts, Us)...>;
+};
+
+template <class A, class... P>
+using any_pairs_list_4 = X<int, int>::Y<A, P...>;
+
+int main() {
+  any_pairs_list_4<int, int> array;
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic4.C 
b/gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic4.C
new file mode 100644
index 00000000000..c5311801a51
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic4.C
@@ -0,0 +1,11 @@
+// PR c++/118104
+// { dg-do compile { target c++11 } }
+
+template<typename... Zs> struct Z { };
+
+template <class... Ts> struct X {
+  template <class... Us> using Y = Z<void(Ts, Us)...>;
+};
+
+template <class A, class... P>
+using foo = X<int, int>::Y<A, P...>;

This testcase seems to basically be a subset of the first one, maybe we
could merge them? e.g. keep the separate class template Z, and also
instantiate foo like in the first testcase.

Merged in the patch below.  They are almost the same but the original
had a "recursive" alias template which I thought was what was confusing
the code.  But that is not the case.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

OK for trunk and backports.

-- >8 --
r12-1094 mentions that adding the assert didn't lead to any regressions
in the testsuite, but this test case demonstrates that we can reach it
with valid code.

Here we arrive in use_pack_expansion_extra_args_p with t which is an
expansion whose pattern is void(Ts, Us) and tparm packs are {Us, Ts},
and parm_packs is { Ts -> <int, int>, Us -> <A, P...> }.  We want to
expand the pack into void(int, A) and void(int, P...).  We compare
int to A, which is fine, but then int to P... which crashes.  But
the code is valid so this patch removes the assert.

        PR c++/118104

gcc/cp/ChangeLog:

        * pt.cc (use_pack_expansion_extra_args_p): Remove an assert.

gcc/testsuite/ChangeLog:

        * g++.dg/cpp0x/alias-decl-variadic3.C: New test.
---
  gcc/cp/pt.cc                                  | 11 +++++++++-
  .../g++.dg/cpp0x/alias-decl-variadic3.C       | 22 +++++++++++++++++++
  2 files changed, 32 insertions(+), 1 deletion(-)
  create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic3.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 8aaae446868..35c68a6e3f2 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -13180,7 +13180,16 @@ use_pack_expansion_extra_args_p (tree t,
if (has_expansion_arg && has_non_expansion_arg)
        {
-         gcc_checking_assert (false);
+         /* We can get here with:
+
+             template <class... Ts> struct X {
+               template <class... Us> using Y = Z<void(Ts, Us)...>;
+             };
+             template <class A, class... P>
+             using foo = X<int, int>::Y<A, P...>;
+
+            where we compare int and A and then the second int and P...,
+            whose expansion-ness doesn't match, but that's OK.  */
          return true;
        }
      }
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic3.C 
b/gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic3.C
new file mode 100644
index 00000000000..077f033d545
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-variadic3.C
@@ -0,0 +1,22 @@
+// PR c++/118104
+// { dg-do compile { target c++11 } }
+
+template<typename... Zs> struct Z { };
+
+template <class... Ts> struct X {
+  template <class... Us> using W = Z<void(Ts, Us)...>;
+  template <class... Us> using Y = X<void(Ts, Us)...>;
+};
+
+template <class A, class... P>
+using foo = X<int, int>::W<A, P...>;
+
+template <class A, class... P>
+using bar = X<int, int>::Y<A, P...>;
+
+void
+g ()
+{
+  foo<int, int> f;
+  bar<int, int> b;
+}

base-commit: 8744d53db1b6816586dac102942c00c105524172

Reply via email to