From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 44F123858417; Fri, 27 Jan 2023 23:17:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 44F123858417 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674861476; bh=ZzRGck29CXZz9qMRhfvwPIvrUGkBepKoglc19zDrt9k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=yLWmwX6LdwVlmOfp/6x/BHzJ2ocYpTxjIjkgERYNLqr/lspZgEzQtLqrXRO0tmgYg yuaaIQ2iMz7+iANsm69QPLqfjlbUeXGEwWY5enSIKkzXz5lSJkicCSwHqukacNs/6v IEUs1uG92zbu0j+fZBy1kz1mv7oAwnSmj54hR+q8= From: "mpolacek at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108158] [11/12/13 Regression] modification of '...' is not a constant expression since r12-2304 Date: Fri, 27 Jan 2023 23:17:56 +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: 13.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: mpolacek at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: mpolacek at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.4 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=3D108158 --- Comment #5 from Marek Polacek --- Candidate fix: diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index be99bec17e7..6718c29b0cd 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -4301,9 +4301,13 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, = tree t, if (!SCALAR_TYPE_P (elem_type)) { new_ctx =3D *ctx; - if (ctx->object) + if (ctx->object + && !same_type_ignoring_top_level_qualifiers_p + (TREE_TYPE (t), TREE_TYPE (ctx->object))) /* If there was no object, don't add one: it could confuse us - into thinking we're modifying a const object. */ + into thinking we're modifying a const object. Similarly, if + the types are the same, replacing .object could lead to a + failure to evaluate it (c++/108158). */ new_ctx.object =3D t; new_ctx.ctor =3D build_constructor (elem_type, NULL); ctx =3D &new_ctx;=