public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-10128] c++: Don't reject GOTO_EXPRs to cdtor_label in potential_constant_expression_1 [PR104513] Date: Wed, 11 May 2022 06:24:46 +0000 (GMT) [thread overview] Message-ID: <20220511062446.F3D1C38515F7@sourceware.org> (raw) https://gcc.gnu.org/g:87cd4bc02f602226922e6c8099a2f4687664bed9 commit r9-10128-g87cd4bc02f602226922e6c8099a2f4687664bed9 Author: Jakub Jelinek <jakub@redhat.com> Date: Mon Feb 14 16:56:15 2022 +0100 c++: Don't reject GOTO_EXPRs to cdtor_label in potential_constant_expression_1 [PR104513] return in ctors on targetm.cxx.cdtor_returns_this () target like arm is emitted as GOTO_EXPR cdtor_label where at cdtor_label it emits RETURN_EXPR with the this. Similarly, in all dtors regardless of targetm.cxx.cdtor_returns_this () a return is emitted similarly. potential_constant_expression_1 was rejecting these gotos and so we incorrectly rejected these testcases, but actual cxx_eval* is apparently handling these just fine. I was a little bit worried that for the destruction of bases we wouldn't evaluate something we should, but as the testcase shows, that is evaluated through try ... finally and there is nothing after the cdtor_label. For arm there is RETURN_EXPR this; but we don't really care about the return value from ctors and dtors during the constexpr evaluation. I must say I don't see much the point of cdtor_labels at all, I'd think that with try ... finally around it for non-arm we could just RETURN_EXPR instead of the GOTO_EXPR and the try/finally gimplification would DTRT, and we could just add the right return value for the arm case. 2022-02-14 Jakub Jelinek <jakub@redhat.com> PR c++/104513 * constexpr.c (potential_constant_expression_1) <case GOTO_EXPR>: Don't punt if returns (target). * g++.dg/cpp1y/constexpr-104513.C: New test. (cherry picked from commit 02a981a8e512934a990d1427d14e8e884409fade) Diff: --- gcc/cp/constexpr.c | 4 ++-- gcc/testsuite/g++.dg/cpp1y/constexpr-104513.C | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 3a35df5a1ee..5744537d8e6 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -6928,8 +6928,8 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, case GOTO_EXPR: { tree *target = &TREE_OPERAND (t, 0); - /* Gotos representing break and continue are OK. */ - if (breaks (target) || continues (target)) + /* Gotos representing break, continue and cdtor return are OK. */ + if (breaks (target) || continues (target) || returns (target)) { *jump_target = *target; return true; diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-104513.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-104513.C new file mode 100644 index 00000000000..4fa78a3e025 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-104513.C @@ -0,0 +1,10 @@ +// PR c++/104513 +// { dg-do compile { target c++14 } } + +struct A { + int a1; + short a2, a3; + long a4; + constexpr A() : a1(42), a2(42), a3(42), a4(42) { return; } +}; +constexpr A a;
reply other threads:[~2022-05-11 6:24 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=20220511062446.F3D1C38515F7@sourceware.org \ --to=jakub@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).