From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5EA443858035; Wed, 27 Oct 2021 07:28:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5EA443858035 From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/102753] ICE in cp_genericize_r on invalid use of pointer to a consteval member function Date: Wed, 27 Oct 2021 07:28: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: 12.0 X-Bugzilla-Keywords: ice-on-invalid-code 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: jakub 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, 27 Oct 2021 07:28:51 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102753 --- Comment #4 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:7473b8a90490e1dcd8fd5f7a92307d79fd2a5f8e commit r12-4731-g7473b8a90490e1dcd8fd5f7a92307d79fd2a5f8e Author: Jakub Jelinek Date: Wed Oct 27 09:08:19 2021 +0200 c++: Reject addresses of immediate functions in constexpr vars inside of immediate functions or consteval if [PR102753] Another thing that wasn't in the previous patch, but I'm wondering whet= her we don't handle it incorrectly. constexpr.c has: /* Check that immediate invocation does not return an expression referencing any immediate function decls. They need to be allowed while parsi= ng immediate functions, but can't leak outside of them. */ if (is_consteval && t !=3D r && (current_function_decl =3D=3D NULL_TREE || !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))) as condition for the discovery of embedded immediate FUNCTION_DECLs (or now PTRMEM_CSTs). If I remove the && (current... ..._decl)) then g++.dg/cpp2a/consteval7.C's struct S { int b; int (*c) (); }; consteval S baz () { return { 5, foo }; } consteval int qux () { S s =3D baz (); return s.b + s.c (); } consteval int quux () { constexpr S s =3D baz (); return s.b + s.c (); } quux line fails, but based on http://eel.is/c++draft/expr.const#11 I wonder if it shouldn't fail (clang++ -std=3Dc++20 rejects it), and be only accepted without the constexpr keyword before S s. Also wonder about e.g. consteval int foo () { return 42; } consteval int bar () { auto fn1 =3D foo; // This must be ok constexpr auto fn2 =3D foo; // Isn't this an error? return fn1 () + fn2 (); } constexpr int baz () { if consteval { auto fn1 =3D foo; // This must be ok constexpr auto fn2 =3D foo; // Isn't this an error? return fn1 () + fn2 (); } return 0; } auto a =3D bar (); static_assert (bar () =3D=3D 84); static_assert (baz () =3D=3D 84); (again, clang++ -std=3Dc++20 rejects the fn2 =3D foo; case, but doesn't implement consteval if, so can't test the other one). For taking address of an immediate function or method if it is taken outside of immediate function context we already have diagnostics about it, but shouldn't the immediate FUNCTION_DECL discovery in cxx_eval_outermost_constant_expression be instead guarded with something like if (is_consteval || in_immediate_context ()) and be done regardless of whether t !=3D r? 2021-10-27 Jakub Jelinek PR c++/102753 * constexpr.c (cxx_eval_outermost_constant_expr): Perform find_immediate_fndecl discovery if is_consteval or in_immediate_context () rather than if is_consteval, t !=3D r and not in immediate function's body. * g++.dg/cpp2a/consteval7.C: Expect diagnostics on quux. * g++.dg/cpp2a/consteval24.C: New test. * g++.dg/cpp23/consteval-if12.C: New test.=