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.

4379. hive::reserve() needs Throws: element adjusted to match block min/max considerations

Section: 23.3.9.3 [hive.capacity] Status: New Submitter: Matt Bentley Opened: 2025-09-17 Last modified: 2025-09-23

Priority: Not Prioritized

View other active issues in [hive.capacity].

View all other issues in [hive.capacity].

View all issues with New status.

Discussion:

This issue comes from Bloomberg as part of their C++26 comments via Incits. To summarize their case, in a call to reserve(n),

if (n > capacity() && capacity() + current-limits.min > max_size()),

reserve should throw, e.g when max_size=100, capacity=80, current-limits.min and current-limits.max are 40 and n=90.

In addition, in the above scenario if we increase max_size() to 140 and n to 130, we can see that although we could add one block with a capacity of current-limits.min, adding another would be impossible; we still cannot make capacity >= n without also being > max_size.

This is currently not stated in the Throws: element. I've implemented the requested additional throws and they are easily achievable.

Proposed resolution:

This wording is relative to N5014.

  1. Modify 23.3.9.3 [hive.capacity] as indicated:

    void reserve(size_type n);
    

    -3- Effects: If n <= capacity() is true, there are no effects. Otherwise increases capacity() by allocating reserved blocks.

    -4- Postconditions: capacity() >= n is true.

    -5- Throws: length_error if ncapacity() cannot be made >= n without being > max_size(), as well as any exceptions thrown by the allocator.

    […]