C++ Logo

std-proposals

Advanced search

Re: Idea: extend forward declarations to include base class(s)

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sat, 22 Feb 2020 11:22:08 -0800
On Friday, 21 February 2020 09:53:34 PST John Yates via Std-Proposals wrote:
> struct D : B;
>
> I am not enough of a language lawyer to know why this would not work and
> whether it might have problems in the presence of multiple base classes.

That only works if B is not forward-declared and maybe not even then. The full
definition is usually needed to determine what adjustment is needed to apply
to the pointers in order to transform a D to a B.

On most ABIs, the first non-virtual base ("primary" base) shares the same top
address as the derived class, so you could convert a D to a B without
adjustment, but not so in the case of:

        struct D : A, B;
or
        struct D : virtual B;

And I am not completely sure even for your case either. First of all, the ABI
is not required to share the top-of-object address of the two classes (though
as the committee meeting in Prague just said, the standard may decide to
mandate things that could break ABI). Second, I am not completely certain
other issues don't mandate knowing the layout of the class in order to do the
pointer adjustment.

Well, it's something the standard could bulldoze through, though, at the
expense of a major ABI break that would require recompiling EVERYTHING C++.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel System Software Products

Received on 2020-02-22 13:24:51