C++ Logo

std-discussion

Advanced search

Re: Legal? Incomplete type "gains" base class on completion.

From: Nicolas Lesser <blitzrakete_at_[hidden]>
Date: Sun, 12 May 2019 21:29:09 +0200
Fabio Fracassi via Std-Discussion wrote:
> consider the following (also on https://gcc.godbolt.org/z/6ikNyq):
>
> structS; // (1)
>
> structU {
> S* sp_;
> U(S* sp) : sp_{sp} {}
> autop() -> int;
> };
>
> structB {
> inti_ = 42;
> autop(inta) -> int{ returna + i_; }
> };
>
> structS : B { // (2) Type S is completed here ... legal to introduce B
> as base?
> autop() -> int{ returnB::p(3); }
> };
>
> autoU::p() -> int{ returnsp_->p(); }
>
> intmain() {
> S s{};
> U u{&s};
> returnu.p();
> }
>
> Is this legal? Reading the standard I do not find anything that either
> forbids it, but neither do I find anything that allows it.
> All compilers that I tried are fine with it, but does anyone know
> whether this is intentional?
>
>
>
>
>
>

Why would it be ill-formed? Also which part exactly are you having a problem with? Is it struct S : B?

If so: There is nothing special going on here that would need special rules in the standard. Just the normal rules for base classes and inheritance make it legal to make S derive from B. It doesn't matter that you are using S before as a pointer.

-- 
- Nicolas

Received on 2019-05-12 14:30:53