This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++26 status.
std::expected should propagate trivialitySection: 22.8.6.4 [expected.object.assign], 22.8.7.4 [expected.void.assign] Status: C++26 Submitter: Jiang An Opened: 2023-12-16 Last modified: 2026-06-09
Priority: 2
View all other issues in [expected.object.assign].
View all issues with C++26 status.
Duplicate of: 4195
Discussion:
Addresses US 135-216 and US 136-217
Currently, only copy and move constructors of std::expected are required to propagate triviality,
while copy and move assignment operators are not. Given that the assignment operators of std::optional
and std::variant are already required to propagate triviality, it seems to me that we should also
apply such requirements for std::expected.
Such changes are being made in libc++ (llvm/llvm-project#74768). And it may be desired to make the triviality improvement portable.
[2024-03-11; Reflector poll]
Set priority to 2 after reflector poll in January 2024. A few votes for Tentatively Ready, others thought it needed more consideration.
[2026-01-29; added links to C++26 NB comments.]
[Croydon 2026-03-25; move to Immediate.]
[Croydon 2026-03-28; Status changed: Immediate → WP.]
Proposed resolution:
This wording is relative to N4971.
Modify 22.8.6.4 [expected.object.assign] as indicated:
constexpr expected& operator=(const expected& rhs);-2- Effects: […]
[…]
-4- Remarks: This operator is defined as deleted unless:
[…]
constexpr expected& operator=(expected&& rhs) noexcept(see below);-5- Constraints: […]
[…]
-8- Remarks: The exception specification is equivalent to:
[…]
Modify 22.8.7.4 [expected.void.assign] as indicated:
constexpr expected& operator=(const expected& rhs);-1- Effects: […]
[…]
-3- Remarks: This operator is defined as deleted unless
is_copy_assignable_v<E>istrueandis_copy_constructible_v<E>istrue.
constexpr expected& operator=(expected&& rhs) noexcept(see below);-4- Effects: […]
[…]
-6- Remarks: The exception specification is equivalent to
is_nothrow_move_constructible_v<E> && is_nothrow_move_assignable_v<E>.-7- This operator is defined as deleted unless
is_move_constructible_v<E>istrueandis_move_assignable_v<E>istrue.