Title
Parenthesized aggregate initialization for new-expressions
Status
tentatively ready
Section
7.6.2.8 [expr.new]
Submitter
Benjamin Sch.

Created on 2025-03-17.00:00:00 last changed 3 days ago

Messages

Date: 2025-10-10.19:52:59

Proposed resolution (approved by CWG 2025-10-10):

  1. Change in 7.6.2.8 [expr.new] bullet 8.4 as follows:

    If the expression in a noptr-new-declarator is present, it is implicitly converted to std::size_t. The value of the expression is invalid if
    • ...
    • the new-initializer is a braced-init-list or a parenthesized expression-list and the number of array elements for which initializers are provided (including the terminating '\0' in a string-literal (5.13.5 [lex.string])) exceeds the number of elements to initialize.
  2. Change in 7.6.2.8 [expr.new] paragraph 9 as follows:

    If the allocated type is an array, the new-initializer is a braced-init-list or a parenthesized expression-list, 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 as follows:
    • If the new-initializer is a braced-init-list, the hypothetical element is copy-initialized from an empty initializer list (9.5.5 [dcl.init.list]).
    • Otherwise, the hypothetical element is value-initialized (9.5.1 [dcl.init.general]).
    [Note 5: The array can contain more elements than there are elements in the braced-init-list new-initializer, requiring initialization of the remainder of the array elements from an empty initializer list as appropriate. —end note]
Date: 2025-10-10.19:52:59

(From submission #685.)

Subclause 7.6.2.8 [expr.new] paragraph 8 and paragraph 9 contain special cases involving aggregate initialization using braced-init-lists, which need to be amended for parenthesized aggregate initialization. The corresponding rules for the initialization of variables are in 9.5.1 [dcl.init.general] bullet 16.5 for arrays and in 9.5.1 [dcl.init.general] bullet 16.6.2.2 for aggregate classes.

Possible resolution (March, 2025) [SUPERSEDED]:

  1. Change in 7.6.2.8 [expr.new] bullet 8.4 as follows:

    If the expression in a noptr-new-declarator is present, it is implicitly converted to std::size_t. The value of the expression is invalid if
    • ...
    • 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 (5.13.5 [lex.string])) in a braced-init-list or parenthesized expression-list exceeds the number of elements to initialize.
  2. Change in 7.6.2.8 [expr.new] paragraph 9 as follows:

    If the allocated type is an array, the new-initializer is a braced-init-list present and is 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 as follows:
    • If the new-initializer is a braced-init-list, the hypothetical element is copy-initialized from an empty initializer list (9.5.5 [dcl.init.list]).
    • If the new-initializer is a parenthesized expression-list, the hypothetical element is value-initialized (9.5.1 [dcl.init.general]).
    [Note 5: The array can contain more elements than there are elements in the braced-init-list new-initializer, requiring initialization of the remainder of the array elements from an empty initializer list as appropriate. —end note]

Possible resolution (per CWG reflector review starting 2025-05-07) [SUPERSEDED]:

  1. Change in 7.6.2.8 [expr.new] bullet 8.4 as follows:

    If the expression in a noptr-new-declarator is present, it is implicitly converted to std::size_t. The value of the expression is invalid if
    • ...
    • 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 (5.13.5 [lex.string])) in a braced-init-list or parenthesized expression-list exceeds the number of elements to initialize.
  2. Change in 7.6.2.8 [expr.new] paragraph 9 as follows:

    If the allocated type is an array, the new-initializer is a braced-init-list present, 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 as follows:
    • If the new-initializer is a braced-init-list, the hypothetical element is copy-initialized from an empty initializer list (9.5.5 [dcl.init.list]).
    • If the new-initializer is a parenthesized expression-list, the hypothetical element is value-initialized (9.5.1 [dcl.init.general]).
    [Note 5: The array can contain more elements than there are elements in the braced-init-list new-initializer, requiring initialization of the remainder of the array elements from an empty initializer list as appropriate. —end note]
History
Date User Action Args
2025-10-10 19:52:59adminsetmessages: + msg8137
2025-10-10 19:52:59adminsetstatus: review -> tentatively ready
2025-09-29 20:37:12adminsetstatus: open -> review
2025-03-17 00:00:00admincreate