Looking for a related defect report
struct X { std::unique_ptr<int> p; constexpr X() { } };
Prior to C ++ 14, this will be poorly formed due to [dcl.constexpr]
For the constexpr constructor, if there is no argument value, so after replacing the call function, each constructor call and the full expression in the mem initializers will be a constant expression (including conversions), the program is poorly formed; no diagnostics required.
Which means that there is some argument (in this case, only an empty set) that can create a constant expression for calling X::X , as in
constexpr X x;
Since std::unique_ptr not a literal type, it has a nontrivial destructor, this is not possible. However, the constexpr report suggested that constexpr constructors constexpr still be well formed in such cases due to this type of use
X x;
Therefore, the record
For a constexpr function or constexpr constructor, which is neither a default nor a template, if there are no argument values, so a function or constructor call can be evaluated by subexpressing the main constant expression or for a constructor, a constant initializer for some object , the program is poorly formed, not diagnostics required.
Translated, this means: the constexpr constructor constexpr well formed as long as it is a constexpr function, and its member initializations are also constexpr functions, even if the type itself can never be constexpr .
Passer by
source share