c++language-lawyerdynamic-memory-allocationallocatorc++23

What will happen if I call `allocate_at_least(0)` according to C++23 standard?


As shown here, the behavior of allocate(0) is unspecified.

So, what will happen if I call allocate_at_least(0) according to C++23 standard? Is the behavior implementation-defined, or will it be treated as allocate(a_non_zero_value)?


Solution

  • [allocator.requirements.general]/44 specifies (emphasis mine):

    Returns: allocation_result<XX::pointer, XX::size_type>{ptr, count} where ptr is memory allocated for an array of count T and such an object is created but array elements are not constructed, such that count ≥ n. If n == 0, the return value is unspecified.

    Thus, the behaviour, just like allocate(0), is unspecified.