std::allocator<T>::allocate_at_least in constant evaluation
Jiang An

Created on 2022-03-22.00:00:00 last changed 6 months ago


Date: 2022-05-17.11:58:16

Proposed resolution:

This wording is relative to N4910.

  1. Modify [allocator.members] as indicated:

    [[nodiscard]] constexpr allocation_result<T*> allocate_at_least(size_t n);

    -6- Mandates: T is not an incomplete type ([basic.types.general]).

    -7- Returns: allocation_result<T*>{ptr, count}, where ptr is a pointer to the initial element of an array of count T and count ≥ n.

    -8- Throws: bad_array_new_length if numeric_limits<size_t>::max() / sizeof(T) < n, or bad_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 returns allocation_result<T*>{allocate(n), n} within the evaluation of a core constant expression.

Date: 2022-05-15.00:00:00

[ 2022-05-17; Reflector poll ]

Set priority to 3 after reflector poll. Suggestion to fix this in Core instead.

Date: 2022-03-22.00:00:00

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.

The MSVC STL implementation returns allocation_result<T*>{allocate(n), n} now. Perhaps we should adopt this strategy for constant evaluation to avoid additional mechanism in the compiler.

Date User Action Args
2022-05-17 11:58:16adminsetmessages: + msg12458
2022-03-26 11:31:30adminsetmessages: + msg12409
2022-03-22 00:00:00admincreate