https://gcc.gnu.org/g:ed6ffc4e62f716d1b31d599d22594dd969da137f

commit r15-1621-ged6ffc4e62f716d1b31d599d22594dd969da137f
Author: Marek Polacek <pola...@redhat.com>
Date:   Fri Jun 14 17:50:29 2024 -0400

    c++: ICE with generic lambda and pack expansion [PR115425]
    
    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.

Diff:
---
 gcc/cp/pt.cc                                  |  2 ++
 gcc/testsuite/g++.dg/cpp2a/lambda-generic12.C | 25 +++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index daa8ac386dc..017cc7fd0ab 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -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
index 00000000000..219529c7c32
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic12.C
@@ -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>();
+}

Reply via email to