------- Comment #2 from paolo dot carlini at oracle dot com  2009-11-16 13:59 
-------
The confusion stems from the way, slightly confusing, in which the example in
the standard is written, which, if considered an actually runnable snippet,
invokes undefined behavior, because destroys the base of D_object two times. If
you change it to something like:

  D D_object, D_object2;
  B* B_ptr = &D_object2;
  std::cout << "begin" << std::endl;
  D_object.B::~B();
  B_ptr->~B();
  std::cout << "end" << std::endl;

Then the example still explain the important role of virtual destructors - that
is, B_ptr->~B() invokes ~D, *not* ~B (after that, ~B is implicitly invoked, as
normally happens in inheritance hierarchies) - but no undefined behavior is
involved.

Talking about undefined behavior, after "Once a destructor is invoked for an
object, the object no longer exists" the (draft C++0x) standard continues ";
the behavior is undefined if the destructor is invoked for an object whose
lifetime has ended": as any undefined behavior, anything can happen, depending
on the actual size of the class being destructet, depending on the diagnostics
enabled in the underlying memory allocation functions, etc.


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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

Reply via email to