This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
std::allocator<T>::allocate_at_least
in constant evaluationSection: 20.2.10.2 [allocator.members] Status: New Submitter: Jiang An Opened: 2022-03-22 Last modified: 2022-05-17
Priority: 3
View all other issues in [allocator.members].
View all issues with New status.
Discussion:
std::allocator<T>::allocate_at_least
is a constexpr function that allocates memory during
constant evaluation, but its restrictions is not clear. Presumably the restrictions are same as those of
std::allocator<T>::allocate
, and we should specify allocate_at_least
in term of allocate
.
allocation_result<T*>{allocate(n), n}
now. Perhaps we
should adopt this strategy for constant evaluation to avoid additional mechanism in the compiler.
[2022-05-17; Reflector poll]
Set priority to 3 after reflector poll. Suggestion to fix this in Core instead.
Proposed resolution:
This wording is relative to N4910.
Modify 20.2.10.2 [allocator.members] as indicated:
[[nodiscard]] constexpr allocation_result<T*> allocate_at_least(size_t n);-6- Mandates:
-7- Returns:T
is not an incomplete type (6.8.1 [basic.types.general]).allocation_result<T*>{ptr, count}
, whereptr
is a pointer to the initial element of an array ofcount T
andcount ≥ n
. -8- Throws:bad_array_new_length
ifnumeric_limits<size_t>::max() / sizeof(T) < n
, orbad_alloc
if the storage cannot be obtained. -9- Remarks: The storage for the array is obtained by calling::operator new
, but it is unspecified when or how often this function is called. This function starts the lifetime of the array object, but not that of any of the array elements. This function returnsallocation_result<T*>{allocate(n), n}
within the evaluation of a core constant expression.