public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Marek Polacek <mpolacek@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8697] c++: ICE with throw inside concept [PR112437] Date: Thu, 1 Feb 2024 14:00:51 +0000 (GMT) [thread overview] Message-ID: <20240201140051.29D603858297@sourceware.org> (raw) https://gcc.gnu.org/g:65b105b4f399559685200e1598ead8c7d0935c04 commit r14-8697-g65b105b4f399559685200e1598ead8c7d0935c04 Author: Marek Polacek <polacek@redhat.com> Date: Wed Jan 31 17:33:26 2024 -0500 c++: ICE with throw inside concept [PR112437] 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. Diff: --- 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(-) diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index a15eda3f5f8c..4937022ff207 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 000000000000..bc3e3b6891ab --- /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 000000000000..b474472de489 --- /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; +}
reply other threads:[~2024-02-01 14:00 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240201140051.29D603858297@sourceware.org \ --to=mpolacek@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).