Re: Is gcc allowed to eliminate writes in a destructor?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10 June 2015 at 09:09, Norbert Lange wrote:
> @Jonathan: Thanks, I couldnt figure this out from the standard, it
> wording would assume that foo is called with a pointer to an object
> whose lifetime ended.

Sorry for not being clear, I was referring specifically to throwing
exceptions from destructors and using RTTI and calling virtual
functions from destructors. Doing those things is not undefined, see
[class.cdtor] p4 and p5.

[class.cdtor] covers what can be done with an object whose destructor
has started but not completed.

> If I understand this correctly, assume I got two classes,Base ->
> Derived and Base has a virtual destr. and a (non-pure) function called
> cleanup, overridden in Derived and accessing members not in Base.
> After construction the object will somewhat look like this:
>
> &VTableDerived
> [members of Derived]
> &VTableBaseD (with Derived::cleanup)
> [members of Base]
>
> After ~Derived() was running, the Object will look like this:
> # &VTableDerived (undefined?)
> # [members of Derived] (undefined?)
> &VTableBaseB (with Base::cleanup)
> [members of Base]
>
> So the vtable of Base gets altered after ~Derived() finished and
> Base::cleanup will be called?

There's only one vtable, not one for Base and one for Derived, but
yes, the vtable gets altered during construction and destruction.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux