Tested x86_64-linux. Pushed to trunk. -- >8 --
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. --- 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 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))); -- 2.45.2