bad_expected_access<void>
member functions should be noexcept
Section: 22.8.5 [expected.bad.void] Status: WP Submitter: Cassio Neri Opened: 2023-12-24 Last modified: 2024-04-02
Priority: Not Prioritized
View all issues with WP status.
Discussion:
According to 17.9.3 [exception]/2:
Each standard library class
T
that derives from classexception
has the following publicly accessible member functions, each of them having a non-throwing exception specification (14.5):
(2.1) — default constructor (unless the class synopsis shows other constructors)
(2.2) — copy constructor
(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
.
[2024-03-12; Reflector poll]
Set status to Tentatively Ready after five votes in favour during reflector poll.
[Tokyo 2024-03-23; Status changed: Voting → WP.]
Proposed resolution:
This wording is relative to N4971.
Modify 22.8.5 [expected.bad.void] as indicated:
namespace std { template<> class bad_expected_access<void> : public exception { protected: 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; ~bad_expected_access(); public: const char* what() const noexcept override; }; }