From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E9AF23858C2C; Thu, 24 Mar 2022 13:31:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E9AF23858C2C From: "ppalka at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/104620] FAIL: g++.dg/cpp23/consteval-if2.C -std=gnu++20 (test for errors) Date: Thu, 24 Mar 2022 13:31: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: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ppalka 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: 12.0 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: Thu, 24 Mar 2022 13:31:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104620 --- Comment #5 from Patrick Palka --- Some context: consider the simplified/extended C++20 testcase (the consteva= l-if seems to be a red herring): consteval int foo(int x) { return x; } template void bar(int x) { constexpr int y =3D 0; foo(8 * x); // #1 foo(8 * y); // #2 } Before r12-7264, we would indeed correctly reject #1 ahead of time (which h= as a non-constant arg), but we would also incorrectly reject #2 (which has a constant arg), because both arguments are wrapped in NON_DEPENDENT_EXPR whi= ch cxx_eval_constant_expr considers to be always non-constant. So essentially= we used to reject the two now-failing tests in consteval-if2.C only by acciden= t. After r12-7264, is_constant_expr returns false for NON_DEPENDENT_EXPR (mirroring cxx_eval_constant_expr) which in particular means that fold_non_dependent_expr no longer tries to check a non-dependent consteval = call ahead of time if it has a "complex" argument (i.e. one that is wrapped in NON_DEPENDENT_EXPR). Thus we no longer reject #1 ahead of time, and we als= o no longer incorrectly reject #2. IMHO this is overall an improvement, since n= ot rejecting #1 ahead of time is a QoI issue, whereas rejecting #2 is a correctness issue. This also fixed PR103443 for a similar reason. (In reply to Jakub Jelinek from comment #3) > So, either build_non_dependent_arg should be made smarter and not wrap ev= en > simple arithmetics etc. where no C++ template-ish trees appear inside of = it > and everything is like in normal non-template-ish code, or we should > reconsider > the r12-7264 case because clearly often we can handle NON_DEPENDENT_EXPR > just fine. I wonder if we can get rid of NON_DEPENDENT_EXPR entirely? I'm not sure if it's at all necessary anymore. Or perhaps we could change tsubst / is_constant_expr / eval_constant_expr to actually look through NON_DEPENDENT_EXPR. These ideas seem out of scope for GCC 12 though :/=