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

3703. Missing requirements for expected<T, E> requires is_void<T>

Section: 22.8.7.1 [expected.void.general] Status: C++23 Submitter: Casey Carter Opened: 2022-05-24 Last modified: 2023-11-22

Priority: 2

View all issues with C++23 status.

Discussion:

The partial specialization expected<T, E> requires is_void<T> specified in 22.8.7.1 [expected.void.general] is missing some template parameter requirements that should have been copied from 22.8.6.1 [expected.object.general]. We should copy the pertinent requirements from the first two paragraphs of the latter subclause into new paragraphs in the first subclause (the pertinent requirement from the third paragraph is already present in 22.8.7.1 [expected.void.general]).

[2022-06-21; Jonathan adds "Member" before "has_val"]

[2022-06-21; Reflector poll]

Set priority to 2 after reflector poll.

[2022-06-21; Reflector poll]

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

[2022-07-15; LWG telecon: move to Ready]

[2022-07-25 Approved at July 2022 virtual plenary. Status changed: Ready → WP.]

Proposed resolution:

This wording is relative to N4910.

[Drafting note: There is some drive-by cleanup that I couldn't resist while touching this wording: (1) strike the redundant "suitably aligned" guarantee, (2) Don't repeat in prose that the exposition-only members are exposition-only.]

  1. Modify 22.8.6.1 [expected.object.general] as indicated:

    -1- Any object of type expected<T, E> either contains a value of type T or a value of type E within its own storage. Implementations are not permitted to use additional storage, such as dynamic memory, to allocate the object of type T or the object of type E. These objects are allocated in a region of the expected<T, E> storage suitably aligned for the types T and E. Members has_val, val, and unex are provided for exposition only. Member has_val indicates whether the expected<T, E> object contains an object of type T.

  2. Modify 22.8.7.1 [expected.void.general] as indicated:

    -?- Any object of type expected<T, E> either represents a value of type T, or contains a value of type E within its own storage. Implementations are not permitted to use additional storage, such as dynamic memory, to allocate the object of type E. Member has_val indicates whether the expected<T, E> object represents a value of type T.

    -?- A program that instantiates the definition of the template expected<T, E> with a type for the E parameter that is not a valid template argument for unexpected is ill-formed.

    -1- E shall meet the requirements of Cpp17Destructible (Table [tab:cpp17.destructible]).