The default constructor of std::chrono::duration is defined as follows:
constexpr duration() = default;
(For example, see cppreference.com or the libstdc++ source.)
However, cppreference.com also says this about constexpr constructors:
A constexpr constructor must satisfy the following requirements:
...
every base class and every non-static member must be initialized, either in the constructors initialization list or by a member brace-or-equal initializer. In addition, every constructor involved must be a constexpr constructor and every clause of every brace-or-equal initializer must be a constant expression
And in case I was confused about default constructors, cppreference.com seems to say that default constructors brought into being with = default aren't defined differently than implicit default constructors.
Yet, the rep type for (most) durations is a bare integer type. So, shouldn't the explicit = default default constructor for duration be equivalent to
constexpr duration() {}
which of course would leave the integer duration::rep member variable uninitialized? And, in fact, isn't the standard behaviour of duration such that default-constructed values are uninitialized? (But I can't find a reference that explicitly says this.)
So how can the = default constructor for duration be constexpr if it leaves a non-static member variable uninitialized? What am I missing?
Aucun commentaire:
Enregistrer un commentaire