From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A0FE138582B0; Tue, 18 Jul 2023 11:39:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A0FE138582B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689680378; bh=QTFCjJkdZ5wtwwE7wv5FSO8R3ni5480p47Qc8vfkIcw=; h=From:To:Subject:Date:From; b=akXADxIIQhrTcaGXKI1Tpi+fus6PRSbouqz8yUnKTF6aA6YE6UvhKfMuaQaQ3XTLX kg9amh12F3KVLNER4QzWKnDy9RBrkbzFTe4vYfFXKfzilcNzYz+srPvD1ZbrnXYZ5S KjgdCeKVDjW3B/GfnZ4fFDDfOL+CmBGg88NotXjQ= From: "pkeir at outlook dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110714] New: constexpr lifetime error: base class this pointer Date: Tue, 18 Jul 2023 11:39:38 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pkeir at outlook dot com X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D110714 Bug ID: 110714 Summary: constexpr lifetime error: base class this pointer Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: pkeir at outlook dot com Target Milestone: --- Compiling the C++20 MRE code below fails: struct Base { constexpr virtual ~Base() {} constexpr Base* get_this() { return this; } int x; }; struct Derived : public Base {}; constexpr bool test() { Derived* pf =3D new Derived; delete pf->get_this(); return true; } constexpr bool b =3D test(); ...with the following error message: 2$ /opt/gcc-latest/bin/g++ -std=3Dc++20 -c ce_base_alloc2.cpp=20 ce_base_alloc2.cpp:17:24: in =E2=80=98constexpr=E2=80=99 expansion of =E2= =80=98test()=E2=80=99 ce_base_alloc2.cpp:13:23: in =E2=80=98constexpr=E2=80=99 expansion of =E2=80=98pf->Derived::.Base::get_this()->Base::~Base()=E2=80=99 ce_base_alloc2.cpp:8:8: error: deallocation of storage that was not previou= sly allocated 8 | struct Derived : public Base {}; | ^~~~~~~ I have tried with GCC trunk (14.0.0) and also version 12.2.0. I suspect that the this pointer in the base class is not tracking the const= expr dynamic allocation. Clang and MSVC both compile successfully. Clang requires the virtual destructor.=