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

2024-10-26


2859. Value-initialization with multiple default constructors

Section: 9.4.1  [dcl.init.general]     Status: DR     Submitter: Brian Bi     Date: 2024-02-09

[Accepted as a DR at the June, 2024 meeting.]

(From submission #501.)

Subclause 9.4.1 [dcl.init.general] paragraph 9 specifies (as modified by issue 2820):

To value-initialize an object of type T means:

Per the specification, no zero-initialization occurs if the class has any user-provided default constructor, even if that constructor is not actually selected for the default initialization. This is observable in a constant expression, where reads of uninitialized data members are ill-formed.

Proposed resolution (approved by CWG 2024-04-05):

  1. Change in 6.7.3 [basic.life] paragraph 1 as follows:

    The lifetime of an object or reference is a runtime property of the object or reference. A variable is said to have vacuous initialization if it is default-initialized, no other initialization is performed, and, if it is of class type or a (possibly multidimensional) array thereof, a trivial constructor of that class type has a trivial default constructor is selected for the default-initialization. The lifetime of an object of type T begins when: ...
  2. Change in 9.4.1 [dcl.init.general] paragraph 9 as follows:

    To value-initialize an object of type T means:
    • If T is a (possibly cv-qualified) class type (Clause 11 [class]), then
      • if T has either no default constructor (11.4.5.2 [class.default.ctor]) or a default constructor that is user-provided or deleted, then the object is default-initialized;
      • otherwise, the object is zero-initialized and then default-initialized.
      let C be the constructor selected to default-initialize the object, if any. If C is not user-provided, the object is first zero-initialized. In all cases, the object is then default-initialized.
    • ...