public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "pkeir at outlook dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-110714-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110714 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 = new Derived; delete pf->get_this(); return true; } constexpr bool b = test(); ...with the following error message: 2$ /opt/gcc-latest/bin/g++ -std=c++20 -c ce_base_alloc2.cpp ce_base_alloc2.cpp:17:24: in ‘constexpr’ expansion of ‘test()’ ce_base_alloc2.cpp:13:23: in ‘constexpr’ expansion of ‘pf->Derived::<anonymous>.Base::get_this()->Base::~Base()’ ce_base_alloc2.cpp:8:8: error: deallocation of storage that was not previously 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 constexpr dynamic allocation. Clang and MSVC both compile successfully. Clang requires the virtual destructor.
next reply other threads:[~2023-07-18 11:39 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-18 11:39 pkeir at outlook dot com [this message] 2023-07-18 12:46 ` [Bug c++/110714] " pinskia at gcc dot gnu.org 2023-07-18 12:58 ` pkeir at outlook dot com 2023-07-18 13:16 ` pkeir at outlook dot com 2024-03-22 0:53 ` redi at gcc dot gnu.org 2024-03-22 0:54 ` redi at gcc dot gnu.org 2024-03-25 21:13 ` ppalka at gcc dot gnu.org
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-110714-4@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).