Skip to content

CWG2895 [dcl.init.general] should ignore cv-qualification of destination type #541

@t3nsor

Description

@t3nsor

Full name of submitter: Brian Bi

Reference (section label): [dcl.init.general]

Issue description: CWG2830 clarified that list-initialization of cv T follows the same rules as list-initialization of T. We need to do something similar for non-list-initialization:

  • p16.3 needs to also apply to arrays of the cv-qualified versions of char8_t, char16_t, etc.
  • p16.8 needs to also apply to cv bool.

Suggested resolution:

Drafting note: This suggested resolution follows the approach in CWG2830, where we strip the cv-qualifiers at the very beginning. This will avoid the need to address the issue again when P3087R0 comes up for Core review.

Edit the preamble of [dcl.init.general]/16:

The semantics of initializers are as follows. The destination type is the cv-unqualified type of the object or reference being initialized and the source type is the type of the initializer expression. If the initializer is not a single (possibly parenthesized) expression, the source type is not defined.

Edit the preamble of [dcl.init.general]/16.6:

Otherwise, if the destination type is a (possibly cv-qualified) class type:

Edit [dcl.init.general]/16.6.1:

If the initializer expression is a prvalue and the cv-unqualified version of the source type is the same class as the class of the destination as the destination type, the initializer expression is used to initialize the destination object.

Edit the preamble of [dcl.init.general]/16.6.2:

Otherwise, if the initialization is direct-initialization, or if it is copy-initialization where the cv-unqualified version of the source type is the same class as, or a derived class of, the class of the destination as or is derived from the destination type, constructors are considered. The applicable constructors are enumerated ([over.match.ctor]), and the best one is chosen through overload resolution ([over.match]). Then:

Edit [dcl.init.general]/16.9:

Otherwise, the initial value of the object being initialized is the (possibly converted) value of the initializer expression. A standard conversion sequence ([conv]) is used to convert the initializer expression to a prvalue of the cv-unqualified version of the destination type; no user-defined conversions are considered. If the conversion cannot be done, the initialization is ill-formed. When initializing a bit-field with a value that it cannot represent, the resulting value of the bit-field is implementation-defined.

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