From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 03DEB3858292; Tue, 27 Sep 2022 01:40:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03DEB3858292 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664242847; bh=EFeZKmIMEqxW3ApzKs8dZ6qRjppDkO38lKcbXc3Gbec=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Bb6CmWniLUQVFLJHU96HrhnhoBdBrD/CxrygNUeRs1YqboTAy6n8LfRrgdQmDftv3 p/mMmPUd06KRjZflygNVS6cvpon2VrLujoFR1V/SJHdlZzDZlpbZFk9LaTxnyoL2mc H2AcotET06+OB0OomzNmJ1yTMstaG/9sO49CBT5E= 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: Tue, 27 Sep 2022 01:40:46 +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 #7 from Johel Ernesto Guerrero Pe=C3=B1a --- This may be related. Assigning to another member doesn't end the lifetime of the active one: https://godbolt.org/z/eMGY5ehnb. ```C++ #include struct symbol { }; constexpr symbol one{}; struct unit { const struct symbol* symbol =3D &one; struct not_one_t { }; union to_the { not_one_t not_one =3D {}; // Omits =C2=B9 from NTTP. int i; to_the() =3D default; constexpr to_the(int i) : i{i} { if (i =3D=3D 1) { // std::destroy_at(&this->i); // On GCC, doesn't help. not_one =3D {}; // std::construct_at(¬_one); // On GCC, initializes `not_one`, doesn't end the lifetime of `i`. } } } exponent =3D {}; constexpr unit(const struct symbol& s) : symbol{&s} { } constexpr unit(const struct symbol& s, auto e) : symbol{&s}, exponent{e} { } }; template void print() { } int main() { constexpr auto U =3D unit{one, 1}; print(); print(); static_assert(&U.exponent.not_one); // static_assert(U.exponent.i =3D=3D 1); // Works on GCC (and MSVC). } ```=