In the current version of the C++ draft (september 2019), paragraph [class.default.ctor]/4 states:
A default constructor that is defaulted and not defined as deleted is implicitly defined when it is odr-used ([basic.def.odr]) to create an object of its class type ([intro.object]), when it is needed for constant evaluation ([expr.const]), or when it is explicitly defaulted after its first declaration. [...]. Before the defaulted default constructor for a class is implicitly defined, all the non-user-provided default constructors for its base classes and its non-static data members shall have been implicitly defined. [ Note: An implicitly-declared default constructor has an exception specification ([except.spec]). An explicitly-defaulted definition might have an implicit exception specification, see [dcl.fct.def]. — end note ]
[class.dtor]/11 specifies a similar restriction for default destructors.
What does the highlighted sentence mean? Is it a restriction on the program or on the implementation (compiler)?
The first sentence of the quoted paragraph states when a defaulted default constructor is implicitly defined (e.g. when it is odr-used). If the highlighted sentence is a restriction on the program, then the following example should be ill-formed, because at (1) the defaulted default constructor of B
is odr-used, therefore it is implicitly defined. However, at this point, the defaulted default constructor of A
has not been implicitly defined, therefore the restriction in the highlighted sentence is not respected. This is because I believe that the defaulted default constructor of A
is odr-used only after the defaulted default constructor of B
is defined. Is this assumption wrong?
struct A {};
struct B : A {};
int main()
{
B b; // (1)
}
Thank you.