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.
std::future and std::shared_future have unimplementable postconditionsSection: 32.10.7 [futures.unique.future], 32.10.8 [futures.shared.future] Status: C++23 Submitter: Jiang An Opened: 2022-10-19 Last modified: 2023-11-22
Priority: 3
View all other issues in [futures.unique.future].
View all issues with C++23 status.
Discussion:
The move assignment operators of std::future and std::shared_future have their postconditions specified as below:
Postconditions:
valid()returns the same value asrhs.valid()returned prior to the assignment.
rhs.valid() == false.
It can be found that when *this and rhs is the same object and this->valid()
is true before the assignment, the postconditions can't be achieved.
[2022-11-01; Reflector poll]
Set priority to 3 after reflector poll.
[2022-11-01; Jonathan provides wording]
[2022-11-07; Reflector poll]
Set status to Tentatively Ready after six votes in favour during reflector poll.
[2022-11-12 Approved at November 2022 meeting in Kona. Status changed: Voting → WP.]
Proposed resolution:
This wording is relative to N4917.
Modify 32.10.7 [futures.unique.future] as indicated:
future& operator=(future&& rhs) noexcept;-11- Effects: If
addressof(rhs) == thisistrue, there are no effects. Otherwise:
- (11.1) — Releases any shared state (32.10.5 [futures.state]).
- (11.2) — move assigns the contents of
rhsto*this.-12- Postconditions:
- (12.1) —
valid()returns the same value asrhs.valid()prior to the assignment.- (12.2) — If
addressof(rhs) == thisisfalse,rhs.valid() == false.
Modify 32.10.8 [futures.shared.future] as indicated:
shared_future& operator=(shared_future&& rhs) noexcept;-13- Effects: If
addressof(rhs) == thisistrue, there are no effects. Otherwise:
- (13.1) — Releases any shared state (32.10.5 [futures.state]).
- (13.2) — move assigns the contents of
rhsto*this.-14- Postconditions:
- (14.1) —
valid()returns the same value asrhs.valid()returned prior to the assignment.- (14.2) — If
addressof(rhs) == thisisfalse,rhs.valid() == false.shared_future& operator=(const shared_future& rhs) noexcept;-15- Effects: If
addressof(rhs) == thisistrue, there are no effects. Otherwise:
- (15.1) — Releases any shared state (32.10.5 [futures.state]).
- (15.2) — assigns the contents of
rhsto*this.[Note 3: As a result,
*thisrefers to the same shared state asrhs(if any). — end note]-16- Postconditions:
valid() == rhs.valid().