From: Jonathan Wakely Date: Thu, 25 Jul 2024 13:17:34 +0000 (+0100) Subject: libstdc++: Add static_assert to std::expected for LWG 3843 and 3940 X-Git-Tag: basepoints/gcc-16~7227 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=r15-2326-gea435261ad58ea;p=thirdparty%2Fgcc.git libstdc++: Add static_assert to std::expected for LWG 3843 and 3940 libstdc++-v3/ChangeLog: * include/std/expected (expected::value): Add assertions for LWG 3843 requirements. (expected::value): Add assertions for LWG 3940 requirements. --- diff --git a/libstdc++-v3/include/std/expected b/libstdc++-v3/include/std/expected index 3c52f7db01e..515a1e6ab8f 100644 --- a/libstdc++-v3/include/std/expected +++ b/libstdc++-v3/include/std/expected @@ -754,6 +754,7 @@ namespace __expected constexpr const _Tp& value() const & { + static_assert( is_copy_constructible_v<_Er> ); if (_M_has_value) [[likely]] return _M_val; _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(_M_unex)); @@ -762,6 +763,7 @@ namespace __expected constexpr _Tp& value() & { + static_assert( is_copy_constructible_v<_Er> ); if (_M_has_value) [[likely]] return _M_val; const auto& __unex = _M_unex; @@ -771,6 +773,8 @@ namespace __expected constexpr const _Tp&& value() const && { + static_assert( is_copy_constructible_v<_Er> ); + static_assert( is_constructible_v<_Er, const _Er&&> ); if (_M_has_value) [[likely]] return std::move(_M_val); _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(std::move(_M_unex))); @@ -779,6 +783,8 @@ namespace __expected constexpr _Tp&& value() && { + static_assert( is_copy_constructible_v<_Er> ); + static_assert( is_constructible_v<_Er, _Er&&> ); if (_M_has_value) [[likely]] return std::move(_M_val); _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(std::move(_M_unex))); @@ -1510,6 +1516,7 @@ namespace __expected constexpr void value() const& { + static_assert( is_copy_constructible_v<_Er> ); if (_M_has_value) [[likely]] return; _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(_M_unex)); @@ -1518,6 +1525,7 @@ namespace __expected constexpr void value() && { + static_assert( is_copy_constructible_v<_Er> ); if (_M_has_value) [[likely]] return; _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(std::move(_M_unex)));