This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52339] using delete ptr1->ptr2 where ptr2 destructor deletes a const ptr1 fails
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 22 Feb 2012 12:48:04 +0000
- Subject: [Bug c++/52339] using delete ptr1->ptr2 where ptr2 destructor deletes a const ptr1 fails
- Auto-submitted: auto-generated
- References: <bug-52339-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52339
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-22 12:48:04 UTC ---
b = b.0;
a = b->a;
D.2361 = a->b;
if (D.2361 != 0B) goto <D.2362>; else goto <D.2363>;
<D.2362>:
D.2364 = a->b;
B::~B (D.2364);
D.2365 = a->b;
operator delete (D.2365);
which is indeed as if written like:
a->b->~B();
operator delete(a->b); // a is already deleted
if 'a' is not a pointer-to-const then instead you get
b = b.0;
a = b->a;
D.2361 = a->b;
if (D.2361 != 0B) goto <D.2362>; else goto <D.2363>;
<D.2362>:
B::~B (D.2361);
operator delete (D.2361);
calling the destructor and operator delete directly on the value of a->b