Title
Constructors “involved in” subobject initialization
Status
c++14
Section
9.2.6 [dcl.constexpr]
Submitter
Daveed Vandevoorde

Created on 2012-12-19.00:00:00 last changed 81 months ago

Messages

Date: 2013-09-15.00:00:00

[Moved to DR at the September, 2013 meeting.]

Date: 2013-08-15.00:00:00

Proposed resolution (August, 2013):

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

...In addition, either its function-body shall be = delete, or it shall satisfy the following constraints:

  • ...

  • for a non-delegating constructor, every constructor involved in initializing selected to initialize non-static data members and base class sub-objects shall be a constexpr constructor.;

  • for a delegating constructor, the target constructor shall be a constexpr constructor.

Date: 2012-12-19.00:00:00

According to 9.2.6 [dcl.constexpr] paragraph 5

For a constexpr constructor, if no argument values exist such that after function invocation substitution, every constructor call and full-expression in the mem-initializers would be a constant expression (including conversions), the program is ill-formed; no diagnostic required.

However, paragraph 4 also says,

every constructor involved in initializing non-static data members and base class sub-objects shall be a constexpr constructor;

violation of which requires a diagnostic. The question is whether a constructor call appearing in a mem-initializer expression is “involved in” the initialization of X::m. Given the “no diagnostic required” status of constructor calls in paragraph 5, the intent of the “involved in” phrasing would appear to be referring to constructors of members with class types and of base-class subobjects, but the wording should be clarified. For example, in a constructor definition like

  constexpr X(): m(f(S())) { }

if S::S() is not constexpr, is a diagnostic required? For another example,

  struct S {
    constexpr S() {}
    S(int);
  };

  struct A { S s; };

  struct C {
    A x;
    constexpr C(): x{ 1 } {}
  }; 

Is S::S(int) “involved?”

History
Date User Action Args
2014-11-24 00:00:00adminsetstatus: drwp -> c++14
2014-03-03 00:00:00adminsetstatus: dr -> drwp
2013-10-14 00:00:00adminsetmessages: + msg4685
2013-10-14 00:00:00adminsetstatus: tentatively ready -> dr
2013-09-03 00:00:00adminsetmessages: + msg4456
2013-09-03 00:00:00adminsetstatus: drafting -> tentatively ready
2013-05-03 00:00:00adminsetstatus: open -> drafting
2012-12-19 00:00:00admincreate