From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 16BF438346B7; Tue, 10 May 2022 08:23:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 16BF438346B7 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-10680] c++: Don't reject GOTO_EXPRs to cdtor_label in potential_constant_expression_1 [PR104513] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: f5b1fcfd69c7a09f661ebec1341f3df34aec4ead X-Git-Newrev: 48ec754a6e157b47ea9bb1c43b0fabab511dbe65 Message-Id: <20220510082357.16BF438346B7@sourceware.org> Date: Tue, 10 May 2022 08:23:57 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 May 2022 08:23:57 -0000 https://gcc.gnu.org/g:48ec754a6e157b47ea9bb1c43b0fabab511dbe65 commit r10-10680-g48ec754a6e157b47ea9bb1c43b0fabab511dbe65 Author: Jakub Jelinek 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 PR c++/104513 * constexpr.c (potential_constant_expression_1) : Don't punt if returns (target). * g++.dg/cpp1y/constexpr-104513.C: New test. * g++.dg/cpp2a/constexpr-dtor12.C: New test. (cherry picked from commit 02a981a8e512934a990d1427d14e8e884409fade) Diff: --- gcc/cp/constexpr.c | 4 ++-- gcc/testsuite/g++.dg/cpp1y/constexpr-104513.C | 10 ++++++++++ gcc/testsuite/g++.dg/cpp2a/constexpr-dtor12.C | 13 +++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index a72b3641e90..72860808d8c 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -8477,8 +8477,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; diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor12.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor12.C new file mode 100644 index 00000000000..19f9099b9a5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor12.C @@ -0,0 +1,13 @@ +// PR c++/104513 +// { dg-do compile { target c++20 } } + +struct S { + constexpr S () : s (nullptr) {} + constexpr ~S () { delete s; } + int *s; +}; +struct T : S { + constexpr T () : S () {} + constexpr ~T () { s = new int (42); return; } +}; +constexpr T t;