199. What does allocate(0) return?

Section: [allocator.requirements] Status: TC1 Submitter: Matt Austern Opened: 1999-11-19 Last modified: 2016-01-28 10:19:27 UTC

Priority: Not Prioritized

View other active issues in [allocator.requirements].

View all other issues in [allocator.requirements].

View all issues with TC1 status.


Suppose that A is a class that conforms to the Allocator requirements of Table 32, and a is an object of class A What should be the return value of a.allocate(0)? Three reasonable possibilities: forbid the argument 0, return a null pointer, or require that the return value be a unique non-null pointer.

Proposed resolution:

Add a note to the allocate row of Table 32: "[Note: If n == 0, the return value is unspecified. --end note]"


A key to understanding this issue is that the ultimate use of allocate() is to construct an iterator, and that iterator for zero length sequences must be the container's past-the-end representation. Since this already implies special case code, it would be over-specification to mandate the return value.