public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52339] New: using delete ptr1->ptr2 where ptr2 destructor deletes a const ptr1 fails
@ 2012-02-22 10:37 rombust at hotmail dot co.uk
  2012-02-22 11:22 ` [Bug c++/52339] " redi at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: rombust at hotmail dot co.uk @ 2012-02-22 10:37 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52339

             Bug #: 52339
           Summary: using delete ptr1->ptr2 where ptr2 destructor deletes
                    a const ptr1 fails
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: rombust@hotmail.co.uk


The following code crashes and triggers the valgrind error with gcc 4.4 and
4.6. With clang it works just fine. And it also works fine if you remove
"const" on line 15 

*******
struct B;
struct A {
  B* b;
};

struct B {
  A* a;
  B() : a(new A{this}) {}
  ~B() { delete a; }
};

int main() {
  B* b = new B;
  // A* a = b->a;
  const A* a = b->a;
  delete a->b;
}
******

I have no idea if is it undefined behaviour to delete a->b if b deletes a.
Expressions should be evaluated only once, but for some reason this line:
  delete a->b;
is basically acting as if was written like:
  a->b->~B();
  operator delete(a->b); // a is already deleted


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

end of thread, other threads:[~2023-12-21  3:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-22 10:37 [Bug c++/52339] New: using delete ptr1->ptr2 where ptr2 destructor deletes a const ptr1 fails rombust at hotmail dot co.uk
2012-02-22 11:22 ` [Bug c++/52339] " redi at gcc dot gnu.org
2012-02-22 13:07 ` redi at gcc dot gnu.org
2023-05-04 11:34 ` redi at gcc dot gnu.org
2023-05-04 11:35 ` redi at gcc dot gnu.org
2023-05-04 12:23 ` jakub at gcc dot gnu.org
2023-05-04 12:45 ` jakub at gcc dot gnu.org
2023-05-04 13:45 ` jakub at gcc dot gnu.org
2023-05-04 16:58 ` joseph at codesourcery dot com
2023-05-04 22:12 ` jason at gcc dot gnu.org
2023-11-09  6:35 ` pinskia at gcc dot gnu.org
2023-12-21  3:18 ` pinskia 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).