public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110714] New: constexpr lifetime error: base class this pointer
@ 2023-07-18 11:39 pkeir at outlook dot com
  2023-07-18 12:46 ` [Bug c++/110714] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: pkeir at outlook dot com @ 2023-07-18 11:39 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-25 21:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-18 11:39 [Bug c++/110714] New: constexpr lifetime error: base class this pointer pkeir at outlook dot com
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

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).