Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
keinflue opened this issue Mar 17, 2025 · 2 comments

Comments

@keinflue
Copy link

keinflue commented Mar 17, 2025

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]).

@keinflue
Copy link
Author

Thinking about it again, I think [expr.new]/9 needs further modifications. For parenthesized aggregate initialization the elements without initializer should be value-initialized, not copy-list-initialized from an empty initializer list. This is also what needs to be checked here.

@jensmaurer
Copy link
Member

CWG3011

@jensmaurer jensmaurer changed the title [expr.new] does not handle parenthesized aggregate initialization in array new CWG3011 [expr.new] does not handle parenthesized aggregate initialization in array new Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants