* [PATCH] c++: ICE with throw inside concept [PR112437]
@ 2024-01-31 23:41 Marek Polacek
2024-02-01 2:48 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2024-01-31 23:41 UTC (permalink / raw)
To: Jason Merrill, GCC Patches
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/13/12?
-- >8 --
We crash in the loop at the end of treat_lvalue_as_rvalue_p for code
like
template <class T>
concept Throwable = requires(T x) { throw x; };
because the code assumes that we eventually reach sk_function_parms or
sk_try and bail, but in a concept we're in a sk_namespace.
We're already checking sk_try so we don't crash in a function-try-block,
but I've added a test anyway.
PR c++/112437
gcc/cp/ChangeLog:
* typeck.cc (treat_lvalue_as_rvalue_p): Bail out on sk_namespace in
the move on throw of parms loop.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-throw1.C: New test.
* g++.dg/eh/throw4.C: New test.
---
gcc/cp/typeck.cc | 4 +++-
gcc/testsuite/g++.dg/cpp2a/concepts-throw1.C | 8 ++++++++
gcc/testsuite/g++.dg/eh/throw4.C | 13 +++++++++++++
3 files changed, 24 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-throw1.C
create mode 100644 gcc/testsuite/g++.dg/eh/throw4.C
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index a15eda3f5f8..4937022ff20 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -10863,7 +10863,9 @@ treat_lvalue_as_rvalue_p (tree expr, bool return_p)
for (tree decl = b->names; decl; decl = TREE_CHAIN (decl))
if (decl == retval)
return set_implicit_rvalue_p (move (expr));
- if (b->kind == sk_function_parms || b->kind == sk_try)
+ if (b->kind == sk_function_parms
+ || b->kind == sk_try
+ || b->kind == sk_namespace)
return NULL_TREE;
}
}
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-throw1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-throw1.C
new file mode 100644
index 00000000000..bc3e3b6891a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-throw1.C
@@ -0,0 +1,8 @@
+// PR c++/112437
+// { dg-do compile { target c++20 } }
+
+struct S {};
+template <class T>
+concept Throwable = requires(T x) { throw x; };
+
+bool a = Throwable<S>;
diff --git a/gcc/testsuite/g++.dg/eh/throw4.C b/gcc/testsuite/g++.dg/eh/throw4.C
new file mode 100644
index 00000000000..b474472de48
--- /dev/null
+++ b/gcc/testsuite/g++.dg/eh/throw4.C
@@ -0,0 +1,13 @@
+// PR c++/112437
+// { dg-do compile }
+
+struct S {};
+
+S
+foo (S s)
+try {
+ throw s;
+}
+catch (...) {
+ throw s;
+}
base-commit: d22d1a9346f27db41459738c6eb404f8f0956e6f
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: ICE with throw inside concept [PR112437]
2024-01-31 23:41 [PATCH] c++: ICE with throw inside concept [PR112437] Marek Polacek
@ 2024-02-01 2:48 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2024-02-01 2:48 UTC (permalink / raw)
To: Marek Polacek, GCC Patches
On 1/31/24 18:41, Marek Polacek wrote:
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/13/12?
OK.
> -- >8 --
> We crash in the loop at the end of treat_lvalue_as_rvalue_p for code
> like
>
> template <class T>
> concept Throwable = requires(T x) { throw x; };
>
> because the code assumes that we eventually reach sk_function_parms or
> sk_try and bail, but in a concept we're in a sk_namespace.
>
> We're already checking sk_try so we don't crash in a function-try-block,
> but I've added a test anyway.
>
> PR c++/112437
>
> gcc/cp/ChangeLog:
>
> * typeck.cc (treat_lvalue_as_rvalue_p): Bail out on sk_namespace in
> the move on throw of parms loop.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/cpp2a/concepts-throw1.C: New test.
> * g++.dg/eh/throw4.C: New test.
> ---
> gcc/cp/typeck.cc | 4 +++-
> gcc/testsuite/g++.dg/cpp2a/concepts-throw1.C | 8 ++++++++
> gcc/testsuite/g++.dg/eh/throw4.C | 13 +++++++++++++
> 3 files changed, 24 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-throw1.C
> create mode 100644 gcc/testsuite/g++.dg/eh/throw4.C
>
> diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
> index a15eda3f5f8..4937022ff20 100644
> --- a/gcc/cp/typeck.cc
> +++ b/gcc/cp/typeck.cc
> @@ -10863,7 +10863,9 @@ treat_lvalue_as_rvalue_p (tree expr, bool return_p)
> for (tree decl = b->names; decl; decl = TREE_CHAIN (decl))
> if (decl == retval)
> return set_implicit_rvalue_p (move (expr));
> - if (b->kind == sk_function_parms || b->kind == sk_try)
> + if (b->kind == sk_function_parms
> + || b->kind == sk_try
> + || b->kind == sk_namespace)
> return NULL_TREE;
> }
> }
> diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-throw1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-throw1.C
> new file mode 100644
> index 00000000000..bc3e3b6891a
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-throw1.C
> @@ -0,0 +1,8 @@
> +// PR c++/112437
> +// { dg-do compile { target c++20 } }
> +
> +struct S {};
> +template <class T>
> +concept Throwable = requires(T x) { throw x; };
> +
> +bool a = Throwable<S>;
> diff --git a/gcc/testsuite/g++.dg/eh/throw4.C b/gcc/testsuite/g++.dg/eh/throw4.C
> new file mode 100644
> index 00000000000..b474472de48
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/eh/throw4.C
> @@ -0,0 +1,13 @@
> +// PR c++/112437
> +// { dg-do compile }
> +
> +struct S {};
> +
> +S
> +foo (S s)
> +try {
> + throw s;
> +}
> +catch (...) {
> + throw s;
> +}
>
> base-commit: d22d1a9346f27db41459738c6eb404f8f0956e6f
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-01 2:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-31 23:41 [PATCH] c++: ICE with throw inside concept [PR112437] Marek Polacek
2024-02-01 2:48 ` 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).