Created on 2015-03-16.00:00:00 last changed 8 months ago
Proposed resolution (approved by CWG 2023-06-16):
Insert a new paragraph before 7.6.2.8 [expr.new] paragraph 9:
If the allocated type is an array, the new-initializer is a braced-init-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 (9.4.5 [dcl.init.list]). [ Note: The array can contain more elements than there are elements in the braced-init-list, requiring initialization of the remainder of the array elements from an empty initializer list. -- end note ]
Objects created by a new-expression have dynamic storage duration (6.7.6.5 [basic.stc.dynamic]). ...
Change in 7.6.2.8 [expr.new] paragraph 25 as follows:
If the new-expression creates an object or an array of objects of class type, access and ambiguity control are done for the allocation function, the deallocation function (6.7.6.5.3 [basic.stc.dynamic.deallocation]), and the constructor (11.4.5 [class.ctor]) selected for the initialization (if any).If the new-expression creates an array of objects of class type, the destructor is potentially invoked (11.4.7 [class.dtor]).
Change in 7.6.2.8 [expr.new] paragraph 28 as follows:
A declaration of a placement deallocation function matches the declaration of a placement allocation function if it has the same number of parameters and, after parameter transformations (9.3.4.6 [dcl.fct]), all parameter types except the first are identical. If the lookup finds a single matching deallocation function, that function will be called; otherwise, no deallocation function will be called. If the lookup finds a usual deallocation function and that function, considered as a placement deallocation function, would have been selected as a match for the allocation function, the program is ill-formed. For a non-placement allocation function, the normal deallocation function lookup is used to find the matching deallocation function (7.6.2.9 [expr.delete]). In any case, the matching deallocation function (if any) shall be non-deleted and accessible from the point where the new-expression appears.
Change in 9.4.1 [dcl.init.general] paragraph 7 as follows:
To default-initialize an object of type T means:
- ...
- If T is an array type, the semantic constraints of default-initializing a hypothetical element shall be met and each element is default-initialized.
- ...
Change in 9.4.1 [dcl.init.general] paragraph 9 as follows:
To value-initialize an object of type T means:
ifIf T is a (possibly cv-qualified) class type (Clause 11 [class]), then
- if T has either no default constructor (11.4.5.2 [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
;.ifIf T is an array type, the semantic constraints of value-initializing a hypothetical element shall be met and each element is value-initialized;.otherwiseOtherwise, the object is zero-initialized.
Additional notes (May, 2023):
It is unclear whether default-initialization is required to be well-formed even for an array with no elements.
[Accepted as a DR at the November, 2023 meeting.]
According to 7.6.2.8 [expr.new] paragraph 25,
If the new-expression creates an object or an array of objects of class type, access and ambiguity control are done for the allocation function, the deallocation function (11.4.11 [class.free]), and the constructor (11.4.5 [class.ctor]).
The mention of “the constructor” here is strange. For the “object of class type” case, access and ambiguity control are done when we perform initialization in paragraph 17, and we might not be calling a constructor anyway (for aggregate initialization). This seems wrong.
For the “array of objects of class type” case, it makes slightly more sense (we need to check the trailing array elements can be default-initialized) but again (a) we aren't necessarily using a constructor, (b) we should say which constructor — and we may need overload resolution to find it, and (c) shouldn't this be part of initialization, so we can distinguish between the cases where we should copy-initialize from {} and the cases where we should default-initialize?
History | |||
---|---|---|---|
Date | User | Action | Args |
2024-04-05 21:43:46 | admin | set | status: dr -> drwp |
2023-12-19 10:15:28 | admin | set | status: ready -> dr |
2023-11-10 14:27:11 | admin | set | status: tentatively ready -> ready |
2023-06-16 16:50:06 | admin | set | messages: + msg7327 |
2023-06-16 16:50:06 | admin | set | status: review -> tentatively ready |
2023-05-28 20:13:31 | admin | set | messages: + msg7299 |
2023-05-28 20:13:31 | admin | set | status: drafting -> review |
2015-03-16 00:00:00 | admin | create |