This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++20 status.

3190. std::allocator::allocate sometimes returns too little storage

Section: 20.2.10.2 [allocator.members] Status: C++20 Submitter: Casey Carter Opened: 2019-02-20 Last modified: 2021-02-25

Priority: 3

View all other issues in [allocator.members].

View all issues with C++20 status.

Discussion:

20.2.10.2 [allocator.members]/2 says:

-2- Returns: A pointer to the initial element of an array of storage of size n * sizeof(T), aligned appropriately for objects of type T.

As in LWG 3038, we should not return too little storage for n objects of size sizeof(T), e.g. when n is SIZE_MAX / 2 and T is short.

[2019-03-05 Priority set to 3 after reflector discussion]

[2019 Cologne Wednesday night]

Status to Ready; will open additional issue to reconcile this and 3038

Proposed resolution:

This wording is relative to N4800.

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

    [[nodiscard]] T* allocate(size_t n);
    

    […]

    -4- Throws: bad_array_new_length if SIZE_MAX / sizeof(T) < n, or bad_alloc if the storage cannot be obtained.