]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: ICE with generic lambda and pack expansion [PR115425]
authorMarek Polacek <polacek@redhat.com>
Fri, 14 Jun 2024 21:50:29 +0000 (17:50 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 25 Jun 2024 19:11:30 +0000 (15:11 -0400)
In r13-272 we hardened the *_PACK_EXPANSION and *_ARGUMENT_PACK macros.
That trips up here because make_pack_expansion returns error_mark_node
and we access that with PACK_EXPANSION_LOCAL_P.

PR c++/115425

gcc/cp/ChangeLog:

* pt.cc (tsubst_pack_expansion): Return error_mark_node if
make_pack_expansion doesn't work out.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-generic12.C: New test.

gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp2a/lambda-generic12.C [new file with mode: 0644]

index daa8ac386dc9512a6e1fe7209236201f97f4c2e3..017cc7fd0abcbf53883fa62b84c65d206d0bd15a 100644 (file)
@@ -13775,6 +13775,8 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain,
       else
        result = tsubst (pattern, args, complain, in_decl);
       result = make_pack_expansion (result, complain);
+      if (result == error_mark_node)
+       return error_mark_node;
       PACK_EXPANSION_LOCAL_P (result) = PACK_EXPANSION_LOCAL_P (t);
       PACK_EXPANSION_SIZEOF_P (result) = PACK_EXPANSION_SIZEOF_P (t);
       if (PACK_EXPANSION_AUTO_P (t))
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic12.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic12.C
new file mode 100644 (file)
index 0000000..219529c
--- /dev/null
@@ -0,0 +1,25 @@
+// PR c++/115425
+// { dg-do compile { target c++20 } }
+
+using size_t = decltype(sizeof(0));
+
+template <int... I>
+struct X {};
+
+template<int... Is>
+void foo(X<Is...>);
+
+template<auto>
+struct S;
+
+template<class T>
+auto test() {
+  constexpr static auto x = foo<X<__integer_pack (0)...>>(); // { dg-error "no matching function" }
+  return []<size_t... Is>(X<Is...>) {
+    (typename S<x[Is]>::type{}, ...);
+  }(X<__integer_pack (0)...>{});
+}
+
+int main() {
+  test<int>();
+}