C++ Logo


Advanced search

Subject: Legal? Incomplete type "gains" base class on completion.
From: Fabio Fracassi (f.fracassi_at_[hidden])
Date: 2019-05-12 10:54:26

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};

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?

STD-DISCUSSION list run by herb.sutter at gmail.com

Older Archives on Google Groups