4276. front() and back() are not hardened for zero-length std::arrays

Section: 23.3.3.5 [array.zero] Status: Tentatively Ready Submitter: Jan Schultke Opened: 2025-06-08 Last modified: 2025-08-26

Priority: Not Prioritized

View other active issues in [array.zero].

View all other issues in [array.zero].

View all issues with Tentatively Ready status.

Discussion:

The intent of P3471 "Standard library hardening" is clearly to provide hardened preconditions for members of sequence containers, including std::array. However, a zero-length std::array dodges this hardening by having undefined behavior for front() and back() explicitly specified in 23.3.3.5 [array.zero] paragraph 3.

Without this paragraph, front() and back() would be hardened as well, as specified in 23.2.4 [sequence.reqmts].

[2025-08-21; Reflector poll]

Set status to Tentatively Ready after eight votes in favour during reflector poll.

Proposed resolution:

This wording is relative to N5008.

  1. Modify 23.3.3.5 [array.zero] as indicated:

    -3- The effect of calling front() or back() for a zero-sized array is undefined.