From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EAB003858D1E; Wed, 20 Apr 2022 19:45:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EAB003858D1E From: "mpolacek at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105321] "non-constant condition" issued for function containing a short-circuited unevaluated non-constant expression Date: Wed, 20 Apr 2022 19:45:51 +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.2.1 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: mpolacek at gcc dot gnu.org 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: --- 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: Wed, 20 Apr 2022 19:45:52 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105321 --- Comment #2 from Marek Polacek --- As you mention, this slightly modified test compiles fine: bool handle_error(); constexpr int echo(int value, bool yes =3D false) noexcept { return (!yes || handle_error()), value; } static_assert(echo(10) =3D=3D 10, ""); In the original test we have =3D (void) (VIEW_CONVERT_EXPR(yes) || handle_error ());, VIEW_CONVERT_EXPR(value); which has a COMPOUND_EXPR, so we get to cxx_eval_constant_expression/COMPOUND_EXPR. The problem here is that we ca= ll=20 7044 /* Check that the LHS is constant and then discard it. */ 7045 cxx_eval_constant_expression (ctx, op0, 7046 true, non_constant_p, overflow_p, 7047 jump_target); where lval is always true, so the PARM_DECL 'yes' is not evaluated. In the working test, we evaluate "!yes" in cxx_eval_unary_expression which evaluates its operand with 3217 tree arg =3D cxx_eval_constant_expression (ctx, orig_arg, /*lval*/fa= lse, 3218 non_constant_p, overflow_p); where lval is false, so the PARM_DECL is evaluated into a constant.=