From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3B87A386EC49; Sat, 6 Mar 2021 22:10:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B87A386EC49 From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99287] std::source_location::function_name breaks constexpr Date: Sat, 06 Mar 2021 22:10:30 +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: 11.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: ppalka at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Mar 2021 22:10:31 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99287 --- Comment #7 from CVS Commits --- The master branch has been updated by Patrick Palka : https://gcc.gnu.org/g:d1bba463bd0d5692b7fa58ee37a61a55b2517456 commit r11-7546-gd1bba463bd0d5692b7fa58ee37a61a55b2517456 Author: Patrick Palka Date: Sat Mar 6 17:09:07 2021 -0500 c++: Fix constexpr evaluation of pre-increment when !lval [PR99287] Here, during cxx_eval_increment_expression (with lval=3Dfalse) of ++__first where __first is &"mystr"[0], we correctly update __first to &"mystr"[1] but we end up returning &"mystr"[0] + 1 instead of &"mystr"[1]. This unreduced return value inhibits other pointer arithmetic folding during later constexpr evaluation, which ultimately causes the constexpr evaluation to fail. It turns out the simplification of &"mystr"[0] + 1 to &"mystr"[1] is performed by cxx_fold_pointer_plus_expression, not by fold_build2. So we perform this simplification during constexpr evaluation of the temporary MODIFY_EXPR (during which we assign to __first the simplified value), but then we return 'mod' which has only been folded via fold_build2 and hasn't gone through cxx_fold_pointer_plus_expressio= n. This patch fixes this by updating 'mod' with the result of the MODIFY_EXPR evaluation appropriately, so that it captures any additional folding of the expression when !lval. We now need to be wary of this evaluation failing and returning e.g. the MODIFY_EXPR or NULL_TREE; it seems checking *non_constant_p should cover our bases here and is generally prudent. gcc/cp/ChangeLog: PR c++/99287 * constexpr.c (cxx_eval_increment_expression): Pass lval when evaluating the MODIFY_EXPR, and update 'mod' with the result of this evaluation. Check *non_constant_p afterwards. For prefix ops, just return 'mod'. gcc/testsuite/ChangeLog: PR c++/99287 * g++.dg/cpp2a/constexpr-99287.C: New test. Co-authored-by: Jakub Jelinek =