From 56ff5f83dda52f73e736a748e43640396d26257b Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 26 Jun 2024 14:15:29 +0100 Subject: [PATCH] libstdc++: Add noexcept to bad_expected_access members (LWG 4031) libstdc++-v3/ChangeLog: * include/std/expected (bad_expected_access): Add noexcept to special member functions, as per LWG 4031. * testsuite/20_util/expected/bad.cc: Check for nothrow copy and move members. --- libstdc++-v3/include/std/expected | 8 ++++---- libstdc++-v3/testsuite/20_util/expected/bad.cc | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/std/expected b/libstdc++-v3/include/std/expected index 2594cfe131c0..3c52f7db01e2 100644 --- a/libstdc++-v3/include/std/expected +++ b/libstdc++-v3/include/std/expected @@ -79,10 +79,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { protected: bad_expected_access() noexcept { } - bad_expected_access(const bad_expected_access&) = default; - bad_expected_access(bad_expected_access&&) = default; - bad_expected_access& operator=(const bad_expected_access&) = default; - bad_expected_access& operator=(bad_expected_access&&) = default; + bad_expected_access(const bad_expected_access&) noexcept = default; + bad_expected_access(bad_expected_access&&) noexcept = default; + bad_expected_access& operator=(const bad_expected_access&) noexcept = default; + bad_expected_access& operator=(bad_expected_access&&) noexcept = default; ~bad_expected_access() = default; public: diff --git a/libstdc++-v3/testsuite/20_util/expected/bad.cc b/libstdc++-v3/testsuite/20_util/expected/bad.cc index c629e149da5c..7e227f904a02 100644 --- a/libstdc++-v3/testsuite/20_util/expected/bad.cc +++ b/libstdc++-v3/testsuite/20_util/expected/bad.cc @@ -12,3 +12,16 @@ test_pr105146() { std::bad_expected_access(E{}); } + +void +test_lwg4031() +{ + struct test_type : std::bad_expected_access { }; + + static_assert( std::is_nothrow_default_constructible_v ); + // LWG 4031. bad_expected_access member functions should be noexcept + static_assert( std::is_nothrow_copy_constructible_v ); + static_assert( std::is_nothrow_move_constructible_v ); + static_assert( std::is_nothrow_copy_assignable_v ); + static_assert( std::is_nothrow_move_assignable_v ); +} -- 2.47.2