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: Tue, 27 Sep 2022 01:40:46 +0000 [thread overview] Message-ID: <bug-102284-4-mr1yYHsmCK@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 #7 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> --- This may be related. Assigning to another member doesn't end the lifetime of the active one: https://godbolt.org/z/eMGY5ehnb. ```C++ #include <memory> struct symbol { }; constexpr symbol one{}; struct unit { const struct symbol* symbol = &one; struct not_one_t { }; union to_the { not_one_t not_one = {}; // Omits ¹ from NTTP. int i; to_the() = default; constexpr to_the(int i) : i{i} { if (i == 1) { // std::destroy_at(&this->i); // On GCC, doesn't help. not_one = {}; // std::construct_at(¬_one); // On GCC, initializes `not_one`, doesn't end the lifetime of `i`. } } } exponent = {}; constexpr unit(const struct symbol& s) : symbol{&s} { } constexpr unit(const struct symbol& s, auto e) : symbol{&s}, exponent{e} { } }; template<auto> void print() { } int main() { constexpr auto U = unit{one, 1}; print<U>(); print<unit{one}>(); static_assert(&U.exponent.not_one); // static_assert(U.exponent.i == 1); // Works on GCC (and MSVC). } ```
prev parent reply other threads:[~2022-09-27 1:40 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 2022-09-27 1:40 ` johelegp at gmail dot com [this message]
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-mr1yYHsmCK@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).