This is P1009R2: Array size deduction in new-expressions, which was implemented for C++20.
Bjarne Stroustrup pointed out the following inconsistency in the C++ language:
double a[]{1,2,3}; // this declaration is OK, ...
double* p = new double[]{1,2,3}; // ...but this one is ill-formed!
Jens Maurer provided the explanation why it doesn’t work: For a new-expression, the expression
inside the square brackets is currently mandatory according to the C++ grammar. When uniform
initialization was introduced for C++11, the rule about deducing the size of the array from the
number of initializers was never extended to the new-expression case. Presumably this was simply
overlooked. There is no fundamental reason why we cannot make this work [...]
Proposed wording
The reported issue is intended as a defect report with the proposed resolution as follows. The effect
of the wording changes should be applied in implementations of all previous versions of C++ where
they apply. [...]
From GCC's C++ Standards Support pages we may note that GCC lists P1009R2 as implemented as of GCC 11, and we may verify that GCC 11 have back-ported the implemented to accept the OP's example as well-formed as far back as C++11.
DEMO (GCC 11 / -std=c++11
).
initializer-list
tag refers tostd::initializer_list
) – Turtledouble* p = new double[]{1,2,3};
as working example. – Socrates