From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9B5563858C20; Mon, 31 Jan 2022 04:23:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B5563858C20 From: "tobi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/98675] Accessing member of temporary outside its lifetime allowed in constexpr function Date: Mon, 31 Jan 2022 04:23:04 +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: 10.2.1 X-Bugzilla-Keywords: accepts-invalid X-Bugzilla-Severity: normal X-Bugzilla-Who: tobi at gcc dot gnu.org 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: cc 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: Mon, 31 Jan 2022 04:23:04 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98675 Tobias Schl=C3=BCter changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |tobi at gcc dot gnu.org --- Comment #2 from Tobias Schl=C3=BCter --- Here's another testcase (derived from code in the Eigen library ) that seem= s to illustrate the same issue. Please follow the compiler explorer link to see a non-constexpr version and its gimple that makes clear that there indeed is a lifetime issue and also clang's error message https://godbolt.org/z/4zoKaoK= a5 struct B; #define CONSTEXPR constexpr #define CONSTEVAL consteval struct A { public: CONSTEXPR A() { m_val =3D 1; } CONSTEXPR A(const A& other) { m_val =3D other.m_val;} CONSTEXPR ~A() {}; CONSTEXPR int val() { return m_val; } int m_val; CONSTEXPR B operator<<(int); }; struct B { A& m_a; CONSTEXPR B(A& ref) : m_a(ref) {} CONSTEXPR B& operator,(int i) { m_a.m_val =3D i; return *this; } CONSTEXPR ~B() { finished(); } CONSTEXPR A finished() { return m_a; } }; CONSTEXPR B A::operator<<(int i) { m_val =3D i; return B(*this); } CONSTEVAL int f() { A a =3D (A() << 1, 2, 3, 4).finished(); return a.val(); } int g() { return f(); }=