Issue 2556: Wide contract for future::share() (original) (raw)
This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++17 status.
2556. Wide contract for future::share()
Section: 32.10.7 [futures.unique.future] Status: C++17 Submitter: Agustín K-ballo Bergé Opened: 2015-11-05 Last modified: 2021-06-06
Priority: 3
View all other issues in [futures.unique.future].
View all issues with C++17 status.
Discussion:
future::share() is not noexcept, it has a narrow contact requiring valid() as per the blanket wording in [futures.unique_future] p3. Its effects, however, are return shared_future<R>(std::move(*this)), which is noexcept as it has a wide contract. If the source future isn't valid then the targetshared_future simply won't be valid either. There appears to be no technical reason preventing future::share()from having a wide contract, and thus being noexcept.
[2016-08-03 Chicago]
Fri AM: Moved to Tentatively Ready
Proposed resolution:
This wording is relative to N4567.
- Change [futures.unique_future] as indicated:
-3- The effect of calling any member function other than the destructor, the move-assignment operator,
share,orvalidon afutureobject for whichvalid() == falseis undefined. [Note: Implementations are encouraged to detect this case and throw an object of typefuture_errorwith an error condition offuture_errc::no_state. — _end note_]namespace std {
template
class future {
public:
[…]
shared_future share() noexcept;
[…]
};
}[…]
shared_future share() noexcept;
-12- Returns:
shared_future<R>(std::move(*this)).-13- Postcondition:
valid() == false.[…]