This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


1911. constexpr constructor with non-literal base class

Section: 9.2.6  [dcl.constexpr]     Status: CD4     Submitter: Richard Smith     Date: 2014-04-13

[Moved to DR at the November, 2014 meeting.]

An example like

  struct X {
    std::unique_ptr<int> p;
    constexpr X() { }
  };

is ill-formed because the X constructor cannot be used in a constant expression, because a constant expression cannot construct an object of a non-literal type like unique_ptr. This prevents use of something like

  X x;

to guarantee constant-initialization.

Proposed resolution (June, 2014):

Change 9.2.6 [dcl.constexpr] paragraph 5 as follows:

For a non-template, non-defaulted constexpr function or a non-template, non-defaulted, non-inheriting constexpr constructor, if no argument values exist such that an invocation of the function or constructor could be an evaluated subexpression of a core constant expression (7.7 [expr.const]), or, for a constructor, a constant initializer for some object (6.9.3.2 [basic.start.static]), the program is ill-formed; no diagnostic required.