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. [...]"
Sentences similar to the one highlighted in the quoted paragraph are present in the sections describing special functions ([class.default.ctor]/4, [class.copy.ctor]/13, [class.copy.assign]/11 and [class.dtor]/11).
What is the exact meaning and the purpose of this sentence?
If this sentence is a restriction on the implementation, then it could be interpreted as:
"If a defaulted default constructor for a class has to be implicitly defined, the implementation also has to implicitly define all the non-user-provided default constructors for its base classes and its non-static data members before the definition of the defaulted default constructor".
Therefore the first sentence in [class.default.ctor]/4 specifies only some contexts where the implementation has to implicitly-define a defaulted default constructor, and then this sentence specifies another such context. Is this the correct interpretation? If so, why is this sentence needed? If this sentence was missing, then the moment a defaulted default constructor is implicitly defined, the default constructors for its base classes and its non-static data members are odr-used (a use inside an implicit definition is still considered an odr-use, correct?), therefore, due to the first sentence of [class.default.ctor]/4, they would be implicitly-defined as well.
However, the wording "shall have been defined" may seem to mean that if a context triggers the generation of an implicit definition of a defaulted default constructor for class A, the implicit definitions of all the non-user-provided default constructors for A's base classes and its non-static data members should have been already generated (due to some other reason, not because of the generation of the implicit definition of A's defaulted default constructor).
In the current version of the C++ draft,, paragraph [class.default.ctor]/4 states:
Sentences similar to the one highlighted in the quoted paragraph are present in the sections describing special functions ([class.default.ctor]/4, [class.copy.ctor]/13, [class.copy.assign]/11 and [class.dtor]/11).
What is the exact meaning and the purpose of this sentence?
If this sentence is a restriction on the implementation, then it could be interpreted as:
"If a defaulted default constructor for a class has to be implicitly defined, the implementation also has to implicitly define all the non-user-provided default constructors for its base classes and its non-static data members before the definition of the defaulted default constructor".
Therefore the first sentence in [class.default.ctor]/4 specifies only some contexts where the implementation has to implicitly-define a defaulted default constructor, and then this sentence specifies another such context. Is this the correct interpretation? If so, why is this sentence needed? If this sentence was missing, then the moment a defaulted default constructor is implicitly defined, the default constructors for its base classes and its non-static data members are odr-used (a use inside an implicit definition is still considered an odr-use, correct?), therefore, due to the first sentence of [class.default.ctor]/4, they would be implicitly-defined as well.
However, the wording "shall have been defined" may seem to mean that if a context triggers the generation of an implicit definition of a defaulted default constructor for class
A
, the implicit definitions of all the non-user-provided default constructors forA
's base classes and its non-static data members should have been already generated (due to some other reason, not because of the generation of the implicit definition ofA
's defaulted default constructor).