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

3162. system_error::system_error(error_code ec) not explicit

Section: 19.5.8.2 [syserr.syserr.members] Status: New Submitter: Peter Dimov Opened: 2018-10-02 Last modified: 2020-04-07

Priority: 3

View all other issues in [syserr.syserr.members].

View all issues with New status.

Discussion:

The constructor for std::system_error taking a single argument of type std::error_code is not marked explicit, which allows implicit conversions from error_code to system_error. I think that this is an oversight and not intentional, and that we should make this constructor explicit.

[2020-04-07 Issue Prioritization]

Priority to 3 after reflector discussion.

Proposed resolution:

This wording is relative to N4762.

  1. Change 19.5.8.1 [syserr.syserr.overview] p2, class system_error synopsis, as indicated

    namespace std {
      class system_error : public runtime_error {
      public:
        system_error(error_code ec, const string& what_arg);
        system_error(error_code ec, const char* what_arg);
        explicit system_error(error_code ec);
        system_error(int ev, const error_category& ecat, const string& what_arg);
        system_error(int ev, const error_category& ecat, const char* what_arg);
        system_error(int ev, const error_category& ecat);
        const error_code& code() const noexcept;
        const char* what() const noexcept override;
      };
    }
    
  2. Change 19.5.8.2 [syserr.syserr.members] as indicated

    explicit system_error(error_code ec);
    

    -5- Effects: […]

    -6- Ensures: […]