Skip to content

CWG3011 [expr.new] does not handle parenthesized aggregate initialization in array new #685

Description

@keinflue

Full name of submitter (unless configured in github; will be published with the issue): Benjamin Sch.

Reference (section label): [expr.new]

Link to reflector thread (if any):

Issue description:

[expr.new] contains specific wording to handle aggregate initialization with braces for array new, e.g.

int n = 2;
new int[n]{1,2,3};

is specified to throw an exception.

However, [expr.new] doesn't seem to have any wording regarding parenthesized aggregate initialization for the analogous situations, e.g.

int n = 2;
new int[n](1,2,3);

Suggested resolution:

Modify [expr.new]/8.4:

the new-initializer is a braced-init-list present and the number of array elements for which initializers are provided (including the terminating '\0' in a string-literal ([lex.string])) exceeds the number of elements to initialize.

Modify [expr.new]/9:

If the allocated type is an array, the new-initializer is a braced-init-list present but not (), and the expression is potentially-evaluated and not a core constant expression, the semantic constraints of copy-initializing a hypothetical element of the array from an empty initializer list are checked ([dcl.init.list]).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions