]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add static_assert to std::expected for LWG 3843 and 3940
authorJonathan Wakely <jwakely@redhat.com>
Thu, 25 Jul 2024 13:17:34 +0000 (14:17 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 25 Jul 2024 22:10:36 +0000 (23:10 +0100)
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

index 3c52f7db01e2663d8ae8d63a82255247c52beffd..515a1e6ab8f5f85971fa73e9451b75fe014b7796 100644 (file)
@@ -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)));