C++ Logo

std-discussion

Advanced search

Re: Access to virtual base class subobjects via derived classes

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 25 Dec 2022 09:07:56 -0300
On Saturday, 24 December 2022 12:55:47 -03 Matthew House via Std-Discussion
wrote:
> Since the A object is a (virtual) base class subobject of the B
> object, and since i is a member subobject of the A object, i is a
> subobject of the B object. Therefore, accessing i in B's constructor
> yields an unspecified value, since it was not obtained from the this
> pointer of B's constructor, but instead from the this pointer of C's
> constructor.

That's an interesting reading. Are you concluding that

  B(&i)

*was* valid and specified because it was obtained from C's this pointer, but
once control transfers to B's constructor, it's no longer valid? This seems to
be the same conclusion in your second example.

I add that this is something UB could do, but not unspecified.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2022-12-25 12:08:04