Is gcc allowed to eliminate writes in a destructor?

Jonathan Wakely jwakely.gcc@gmail.com
Wed Jun 10 12:51:00 GMT 2015


On 10 June 2015 at 12:47, Norbert Lange wrote:
> if you mean vtable gets altered you mean the pointer is directed to
> another vtable?

Yes.

I should have said the vptr is altered, to refer to a different vtable.

What I mean by "there's only one vtable" is that an object has a
single vptr, to a single vtable. Which vtable it points to depends on
what stage of its lifetime it is at.

During construction of the Base sub-object the object will somewhat
look like this:

&VTableBase
[members of Base]
[uninitialized storage for members of Derived]

then when the Derived constructor runs it looks like this:

&VTableDerived
[members of Base]
[members of Derived]

After ~Derived() completes:

&VTableBase
[members of Base]
[uninitialized storage for members of Derived]

and after ~Base() completes the object is no more.



More information about the Gcc-help mailing list