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

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

Section: 20.10.10.1 [allocator.members] Status: WP Submitter: Casey Carter Opened: 2019-02-20 Last modified: 2019-11-19

Priority: 3

View all other issues in [allocator.members].

View all issues with WP status.

Discussion:

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