From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 913E73858D38; Sat, 24 Sep 2022 20:11:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 913E73858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664050284; bh=eRvyz4T0HtTexLy7ajbDfSeYZio8Mbgt1on9xYN+eiQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=lCBRaVhPM2LgMqpppF79IqL0WbSShWQhDPer/kG+6VDxPVvpbicrh3eNTwsdrqo0p ymz20yJ8mfiOLT3PLsyrJWHFGtnN26yYJZoIiVUpVIJ0xyCP6lie/nYZDSJHQG8RKc TTdiUIh7cbUzDlK5GMV6qgu+XW/99w7vhyVwX5tI= From: "johelegp at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/102284] Can access object outside of its lifetime during constant evaluation Date: Sat, 24 Sep 2022 20:11:23 +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: accepts-invalid X-Bugzilla-Severity: normal X-Bugzilla-Who: johelegp at gmail dot com 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102284 --- Comment #6 from Johel Ernesto Guerrero Pe=C3=B1a --- Another example. Simplified: https://godbolt.org/z/z781c56PM. ```C++ struct ratio { int numerator; }; template struct constant; template concept constant_invocable =3D requires { typename constant<(F(), 0)>; }; static_assert(not constant_invocable<[] { ratio r; (void)int{r.*&ratio::numerator}; }>); ``` ``` :9:15: error: static assertion failed 9 | static_assert(not constant_invocable<[] { | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ 10 | ratio r; | ~~~~~~~~=20=20=20=20=20 11 | (void)int{r.*&ratio::numerator}; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 12 | }>); | ~~=20=20=20=20=20=20=20=20=20=20=20=20=20 Compiler returned: 1 ``` Found while opening https://github.com/llvm/llvm-project/issues/57958: https://godbolt.org/z/KWfvEnaae. ```C++ #include #include #include #include struct ratio { std::intmax_t numerator; std::intmax_t denominator{1}; }; template concept constant_invocable =3D requires { typename std::integral_constant; }; template requires std::is_member_object_pointer_v inline constexpr bool default_initialization_leaves_uninitialized =3D [](M T::*) { return not constant_invocable<[]() { T v; (void)M{v.*P}; }>; }(P); static_assert(default_initialization_leaves_uninitialized<&ratio::numerator= >); static_assert(not default_initialization_leaves_uninitialized<&ratio::denominator>); ``` ``` :22:15: error: static assertion failed 22 | static_assert(default_initialization_leaves_uninitialized<&ratio::numerator= >); |=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Compiler returned: 1 ```=