public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: ICE with generic lambda and pack expansion [PR115425]
@ 2024-06-17 18:17 Marek Polacek
  2024-06-25  2:12 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2024-06-17 18:17 UTC (permalink / raw)
  To: Jason Merrill, GCC Patches

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

-- >8 --
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                                  |  2 ++
 gcc/testsuite/g++.dg/cpp2a/lambda-generic12.C | 25 +++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic12.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 607753ae6b7..e676372f75b 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>();
+}

base-commit: b63c7d92012f92e0517190cf263d29bbef8a06bf
-- 
2.45.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++: ICE with generic lambda and pack expansion [PR115425]
  2024-06-17 18:17 [PATCH] c++: ICE with generic lambda and pack expansion [PR115425] Marek Polacek
@ 2024-06-25  2:12 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2024-06-25  2:12 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches

On 6/17/24 14:17, Marek Polacek wrote:
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

OK.

> -- >8 --
> 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                                  |  2 ++
>   gcc/testsuite/g++.dg/cpp2a/lambda-generic12.C | 25 +++++++++++++++++++
>   2 files changed, 27 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic12.C
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 607753ae6b7..e676372f75b 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>();
> +}
> 
> base-commit: b63c7d92012f92e0517190cf263d29bbef8a06bf


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-06-25  2:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-17 18:17 [PATCH] c++: ICE with generic lambda and pack expansion [PR115425] Marek Polacek
2024-06-25  2:12 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).