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.

3684. std::allocator<T>::allocate_at_least in constant evaluation

Section: 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.

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.

[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.

  1. Modify 20.2.10.2 [allocator.members] as indicated:

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

    -6- Mandates: T is not an incomplete type (6.8.1 [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.