From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C42E03858D1E; Sat, 24 Dec 2022 22:53:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C42E03858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671922390; bh=dc7WHqepwiYAP6Oa/Z0xdga8ZPLQrvxWnHws0EkiT7E=; h=From:To:Subject:Date:In-Reply-To:References:From; b=vr4dGNTdNHXMgqqxFmhB+GqxOwSCAmyxuxTh7xzkok1ePANOEoS+kmt3Txa4u5FWX Voe8VIlOTbxbKO27KsoaZhftXRB3qKGHCZzvLWHKXz6VJaK78yQ/RneIWdQks1NTQJ 6czgIbILFJaWCjl9mTH2wQxLbm5Hjq/DzfmiP5q8= From: "StevenSun2021 at hotmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108218] [12/13 Regression] Constant arguments in the new expression is not checked in unevaluated operand Date: Sat, 24 Dec 2022 22:53:09 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: accepts-invalid, needs-bisection, rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: StevenSun2021 at hotmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108218 --- Comment #7 from Steven Sun --- I got one simple idea as a workaround. I do not have the resources to do the tests. I agree anyone to take the following patch or the idea. >From 35b4186a0ed3671de603bed6df5fb1156f087581 Mon Sep 17 00:00:00 2001 From: Steven Sun Date: Sun, 25 Dec 2022 06:44:43 +0800 Subject: [PATCH] c++: escape unevaluated context in new-expression --- gcc/cp/init.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index b49a7ca9169..974ea95959e 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -3929,7 +3929,12 @@ build_new (location_t loc, vec **placem= ent, tree type, /* Try to determine the constant value only for the purposes of the diagnostic below but continue to use the original value and handle const folding later. */ + /* Escape the possible unevaluated context. Constant folding does + not work in unevaluated context, but is required in nelts. */ + int old_cp_unevaluated_operand =3D cp_unevaluated_operand; + cp_unevaluated_operand =3D false; const_tree cst_nelts =3D fold_non_dependent_expr (nelts, complain); + cp_unevaluated_operand =3D old_cp_unevaluated_operand; /* The expression in a noptr-new-declarator is erroneous if it's of non-class type and its value before converting to std::size_t is --=20 2.34.1=