public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "johelegp at gmail dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-102284-4-YVD1pWid8d@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-102284-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102284 --- Comment #6 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> --- Another example. Simplified: https://godbolt.org/z/z781c56PM. ```C++ struct ratio { int numerator; }; template<auto> struct constant; template<auto F> concept constant_invocable = requires { typename constant<(F(), 0)>; }; static_assert(not constant_invocable<[] { ratio r; (void)int{r.*&ratio::numerator}; }>); ``` ``` <source>:9:15: error: static assertion failed 9 | static_assert(not constant_invocable<[] { | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ 10 | ratio r; | ~~~~~~~~ 11 | (void)int{r.*&ratio::numerator}; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 12 | }>); | ~~ Compiler returned: 1 ``` Found while opening https://github.com/llvm/llvm-project/issues/57958: https://godbolt.org/z/KWfvEnaae. ```C++ #include <concepts> #include <cstdint> #include <functional> #include <type_traits> struct ratio { std::intmax_t numerator; std::intmax_t denominator{1}; }; template<auto F> concept constant_invocable = requires { typename std::integral_constant<int, (F(), 0)>; }; template<auto P> requires std::is_member_object_pointer_v<decltype(P)> inline constexpr bool default_initialization_leaves_uninitialized = []<class T, class M>(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>); ``` ``` <source>:22:15: error: static assertion failed 22 | static_assert(default_initialization_leaves_uninitialized<&ratio::numerator>); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Compiler returned: 1 ```
next prev parent reply other threads:[~2022-09-24 20:11 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-09-10 20:57 [Bug c++/102284] New: " johelegp at gmail dot com 2021-09-10 21:23 ` [Bug c++/102284] " johelegp at gmail dot com 2021-09-10 21:24 ` johelegp at gmail dot com 2021-09-10 21:26 ` pinskia at gcc dot gnu.org 2021-09-11 1:04 ` johelegp at gmail dot com 2022-01-17 11:12 ` pinskia at gcc dot gnu.org 2022-09-24 20:11 ` johelegp at gmail dot com [this message] 2022-09-27 1:40 ` johelegp at gmail dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-102284-4-YVD1pWid8d@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).