Title
Prohibit error_code construction from rvalues of error_category
Status
new
Section
[syserr.errcode.overview]
Submitter
Antony Polukhin

Created on 2018-01-24.00:00:00 last changed 11 hours ago

Messages

Date: 2026-06-10.14:20:42

Proposed resolution:

This wording is relative to N5060.

  1. Modify [syserr.errcode.overview] as indicated:

    namespace std {
      class error_code {
      public:
        // [syserr.errcode.constructors], constructors
        […]
        error_code(int val, const error_category& cat) noexcept;
        error_code(int val, const error_category&& cat) = delete;
        […]
        // [syserr.errcode.modifiers], modifiers
        void assign(int val, const error_category& cat) noexcept;
        void assign(int val, const error_category&& cat) = delete;
        […]
      };
      […]
    }
    
  2. Modify [syserr.errcondition.overview] as indicated:

    namespace std {
      class error_condition {
      public:
        // [syserr.errcondition.constructors], constructors
        […]
        error_condition(int val, const error_category& cat) noexcept;
        error_condition(int val, const error_category&& cat) = delete;
        […]
        // [syserr.errcondition.modifiers], modifiers
        void assign(int val, const error_category& cat) noexcept;
        void assign(int val, const error_category&& cat) = delete;
        […]
      };
      […]
    }
    
Date: 2026-06-15.00:00:00

[ 2026-06-10; Tim provides new wording ]

Date: 2026-06-10.14:20:42

[ Brno 2026-06-10; LWG agreed this is an improvement, need to change `error_condition` too. ]

This wording is relative to N4713.

  1. Modify [syserr.errcode.overview] as indicated:

    namespace std {
      class error_code {
      public:
        // [syserr.errcode.constructors], constructors
        […]
        error_code(int val, const error_category& cat) noexcept;
        error_code(int val, const error_category&& cat) = delete;
        […]
        // [syserr.errcode.modifiers], modifiers
        void assign(int val, const error_category& cat) noexcept;
        void assign(int val, const error_category&& cat) = delete;
        […]
      };
      […]
    }
    
Date: 2018-06-18.00:00:00

[ 2018-06-18 after reflector discussion ]

Priority set to 3

Date: 2018-01-24.00:00:00

Constructor error_code(int val, const error_category& cat) and member function void assign(int val, const error_category& cat) could be misused if a custom error_category is provided:

error_code ec{1, test_category{}}; // ec holds a pointer/reference to a temporary
History
Date User Action Args
2026-06-10 14:20:42adminsetmessages: + msg16420
2026-06-10 12:38:44adminsetmessages: + msg16412
2018-06-19 05:49:11adminsetmessages: + msg9926
2018-01-24 20:42:01adminsetmessages: + msg9632
2018-01-24 00:00:00admincreate