https://gcc.gnu.org/g:ea435261ad58ea3eb811cbd16d085976964bff2c
commit r15-2326-gea435261ad58ea3eb811cbd16d085976964bff2c Author: Jonathan Wakely <jwak...@redhat.com> Date: Thu Jul 25 14:17:34 2024 +0100 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<cv void, E>::value): Add assertions for LWG 3940 requirements. Diff: --- libstdc++-v3/include/std/expected | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libstdc++-v3/include/std/expected b/libstdc++-v3/include/std/expected index 3c52f7db01e2..515a1e6ab8f5 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)));