4031. bad_expected_access<void> member functions should be noexcept

Section: 22.8.5 [expected.bad.void] Status: New Submitter: Cassio Neri Opened: 2023-12-24 Last modified: 2024-01-13 13:25:14 UTC

Priority: Not Prioritized

View all issues with New status.


According to 17.9.3 [exception]/2:

Each standard library class T that derives from class exception has the following publicly accessible member functions, each of them having a non-throwing exception specification (14.5):

  1. (2.1) — default constructor (unless the class synopsis shows other constructors)

  2. (2.2) — copy constructor

  3. (2.3) — copy assignment operator

For good reasons, bad_expected_access<void> overrules from this general rule by protecting its special member functions. However, there's no reason these functions should not be noexcept.

Proposed resolution:

This wording is relative to N4971.

  1. Modify 22.8.5 [expected.bad.void] as indicated:

    namespace std {
      class bad_expected_access<void> : public exception {
        bad_expected_access() noexcept;
        bad_expected_access(const bad_expected_access&) noexcept;
        bad_expected_access(bad_expected_access&&) noexcept;
        bad_expected_access& operator=(const bad_expected_access&) noexcept;
        bad_expected_access& operator=(bad_expected_access&&) noexcept;
        const char* what() const noexcept override;