diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2024-07-25 14:17:34 +0100 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2024-07-28 19:05:58 +0200 |
commit | 4c58169086fd844cc725d3b56077dd2b2eb962d6 (patch) | |
tree | 1c24a11bf4e661d40eac6ffdae72d10e2732bc3c | |
parent | 436ef665d89e3fc5cc6562dc52e8178cb1034846 (diff) | |
download | gcc-4c58169086fd844cc725d3b56077dd2b2eb962d6.zip gcc-4c58169086fd844cc725d3b56077dd2b2eb962d6.tar.gz gcc-4c58169086fd844cc725d3b56077dd2b2eb962d6.tar.bz2 |
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.
-rw-r--r-- | libstdc++-v3/include/std/expected | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libstdc++-v3/include/std/expected b/libstdc++-v3/include/std/expected index 3c52f7d..515a1e6 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))); |