C++ Logo

std-discussion

Advanced search

Implicit definition of special functions

From: Maris Razvan <razvyboy2004_at_[hidden]>
Date: Wed, 18 Sep 2019 22:34:51 +0300
In the current version of the C++ draft (september 2019), paragraph
[class.default.ctor]/4
(http://www.eel.is/c++draft/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. [...]"

What is the meaning and the purpose of the sentence "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"?

I found that restriction even in N1905 (published in 2005), for
exactly four constructs: implicitly-declared default constructor,
implicitly-declared destructor, implicitly-declared copy constructor
and implicitly-declared copy assignment operator.

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 the sentence "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" 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,
therefore, due to the first sentence of [class.default.ctor]/4, they
would be implicitly-defined as well.

Thank you.

Received on 2019-09-18 14:37:11