Skip to content

[dcl.init.general] Could the definition of value-initialization be simplified? #5084

Closed
@cpplearner

Description

@cpplearner

[dcl.init.general]:

To value-initialize an object of type T means:

  • if T is a (possibly cv-qualified) class type ([class]), then
    • if T has either no default constructor ([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;
  • [...]

It seems that if T has no default constructor, then it can't meet the semantic constraints for default-initialization, and the "otherwise" branch correctly makes it ill-formed. (It doesn't matter whether zero-initialization is performed or not, since the initialization is ill-formed either way.)

CWG 1301 adds the "no default constructor" part. When CWG 1301 was adopted, the "otherwise" branch was not specified to check the semantic constraints for default-initialization (which was changed later by CWG 1507). Now that the "otherwise" branch does the right thing, I think it's not necessary to handle the "no default constructor" in the "if" branch.

Suggestion:

To value-initialize an object of type T means:

  • if T is a (possibly cv-qualified) class type ([class]), then
    • if T has either no default constructor ([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;
  • [...]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions