Title
Value-initialization and default constructors
Status
drwp
Section
9.4.1 [dcl.init.general]
Submitter
Shafik Yaghmour

Created on 2023-10-31.00:00:00 last changed 5 months ago

Messages

Date: 2024-01-21.13:30:12

Proposed resolution (approved by CWG 2024-01-19):

Change in 9.4.1 [dcl.init.general] bullet 9.1.2 as follows:

  • ...
  • otherwise, the object is zero-initialized and the semantic constraints for default-initialization are checked, and if T has a non-trivial default constructor, the object is then default-initialized;
Date: 2024-03-15.00:00:00

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

Subclause 9.4.1 [dcl.init.general] paragraph 9 specifies:

To value-initialize an object of type T means:
  • if T is a (possibly cv-qualified) class type (Clause 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 the semantic constraints for default-initialization are checked, and if T has a non-trivial default constructor, the object is default-initialized;
  • if T is an array type, ...

The specification about checking the semantic constraints and invoking only non-trivial default constructors is overly convoluted. Omitting a call to a trivial constructor is an as-if optimization that should not be prescribed by the standard.

History
Date User Action Args
2024-07-20 13:52:34adminsetstatus: dr -> drwp
2024-04-05 21:43:46adminsetstatus: ready -> dr
2024-03-20 14:10:31adminsetstatus: tentatively ready -> ready
2024-01-21 13:30:12adminsetmessages: + msg7573
2024-01-21 13:30:12adminsetstatus: open -> tentatively ready
2023-10-31 00:00:00admincreate