C++ Logo

std-discussion

Advanced search

Re: Access to virtual base class subobjects via derived classes

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 26 Dec 2022 09:05:04 -0300
On Monday, 26 December 2022 00:58:10 -03 Matthew House via Std-Discussion
wrote:
> I was unaware of the discussion on Cpplang (or, for that matter, of
> the existence of Cpplang); I independently stumbled on this oddity
> while trying to build a mental model of which operations can be
> performed on objects at each point of their construction. I should
> probably look into that Cpplang issue, if it's relevant here.

FYI, Arthur filed a bug against GCC at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108216

The original question in #standardese was this source code:

struct A {
    virtual void f();
};

struct B : virtual A {};

struct C : virtual A {
    C(B* p) {
        A* q = p; // <---
    }
};

struct D : B, C {
    D(): C(this) {}
};

Which when compiled with GCC does produce a nonsensical pointer (it's just
over 4 MB away from where it should be, on testing). Clang seems to be
similarly affected, but only if the bases aren't empty).

And yet everyone who looks at this code says that it looks correct and valid.
-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2022-12-26 12:05:07