P0517r0
Make future_error Constructible

Published Proposal,

This version:
http://wg21.link/P0517r0
Author:
(Lawrence Berkeley National Laboratory)
Audience:
SG1, LEWG, LWG
Toggle Diffs:
Project:
ISO JTC1/SC22/WG21: Programming Language C++

This paper proposes a resolution to C++17 CD comment US 163, which requests the addition of a constructor to future_error. It is related to but does not overlap with the proposed resolution to [LWG2556], which is tentatively ready as of November 10th, 2016.

1. US 163

The constructor for future_error should not be exposition only - this is the only exception class in the standard library that users have no clearly specified way to throw themselves. If we want the exception class to be limited to the standard library, at least make the exposition-only constructor private.

2. SG1 and LEWG Response to US 163

SG1’s tentative consensus was to make the constructor not-exposition-only and public. SG1 deferred to LEWG and LWG for the final determination with unanimous consent. LEWG forwarded this paper to LWG with unanimous consent.

3. LWG Feedback

LWG made the following changes:

LWG took one straw poll:

Straw Poll: Make the future_error constructor’s parameter an future_errc.

F N A
11 3 0

⟹ Consensus to make the constructor parameter a future_errc.

There was unanimous consent in LWG to move this paper at the Issaquah 2016 Friday plenary.

4. Proposed Wording

The proposed changes are relative to [N4604], the Committee Draft for C++17.

Apply the following change to the class definition of future_error in 30.6.3 [futures.future_error]:

namespace std {
  class future_error : public logic_error {
  public:
    explicit future_error(error_code ecfuture_errc e); // exposition only

    const error_code& code() const noexcept;
    const char* what() const noexcept;
  private: 
    error_code ec_; // exposition only
  };
}

Add the following member definition to 30.6.3 [futures.future_error] directly after the class definition of future_error:

explicit future_error(future_errc e);

Effects: Constructs an object of class future_error and initializes ec_ with make_error_code(e).

Apply the following change to the definition of future_error::code() in 30.6.3 [futures.future_error]:

const error_code& code() const noexcept;

Returns: The value of ec that was passed to the object’s constructor. ec_.

References

Informative References

[LWG2556]
Agustín K-ballo Bergé. Wide contract for future::share(). Tentatively Ready. URL: http://cplusplus.github.io/LWG/lwg-active.html#2556
[N4604]
Richard Smith. C++17 CD Ballot Document. 12 July 2016. URL: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4604.pdf