Title
constexpr constructor with non-literal base class
Status
cd4
Section
9.2.6 [dcl.constexpr]
Submitter
Richard Smith

Created on 2014-04-13.00:00:00 last changed 95 months ago

Messages

Date: 2014-11-15.00:00:00

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

Date: 2014-06-15.00:00:00

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.
Date: 2014-07-07.00:00:00

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.

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: drwp -> cd4
2015-05-25 00:00:00adminsetstatus: dr -> drwp
2015-04-13 00:00:00adminsetmessages: + msg5359
2014-11-24 00:00:00adminsetstatus: ready -> dr
2014-07-07 00:00:00adminsetmessages: + msg5065
2014-07-07 00:00:00adminsetstatus: open -> ready
2014-04-13 00:00:00admincreate