]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Remove unnecessary variant member in std::expected
authorJonathan Wakely <jwakely@redhat.com>
Tue, 1 Nov 2022 13:47:24 +0000 (13:47 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 2 Nov 2022 12:54:16 +0000 (12:54 +0000)
Hui Xie pointed out that we don't need a dummy member in the union,
because all constructors always initialize either _M_val or _M_unex.

We still need the _M_void member of the expected<void, E>
specialization, because the constructor has to initialize something when
not using the _M_unex member.

libstdc++-v3/ChangeLog:

* include/std/expected (expected::_M_invalid): Remove.

libstdc++-v3/include/std/expected

index 3ee13aa95f6657a6474aebc1cfc65286d97d59d1..e491ce41591e17d220e70ea6a1604783d7a89b88 100644 (file)
@@ -359,7 +359,7 @@ namespace __expected
       requires is_copy_constructible_v<_Tp> && is_copy_constructible_v<_Er>
       && (!is_trivially_copy_constructible_v<_Tp>
          || !is_trivially_copy_constructible_v<_Er>)
-      : _M_invalid(), _M_has_value(__x._M_has_value)
+      : _M_has_value(__x._M_has_value)
       {
        if (_M_has_value)
          std::construct_at(__builtin_addressof(_M_val), __x._M_val);
@@ -376,7 +376,7 @@ namespace __expected
       requires is_move_constructible_v<_Tp> && is_move_constructible_v<_Er>
       && (!is_trivially_move_constructible_v<_Tp>
          || !is_trivially_move_constructible_v<_Er>)
-      : _M_invalid(), _M_has_value(__x._M_has_value)
+      : _M_has_value(__x._M_has_value)
       {
        if (_M_has_value)
          std::construct_at(__builtin_addressof(_M_val),
@@ -394,7 +394,7 @@ namespace __expected
        expected(const expected<_Up, _Gr>& __x)
        noexcept(__and_v<is_nothrow_constructible<_Tp, const _Up&>,
                         is_nothrow_constructible<_Er, const _Gr&>>)
-       : _M_invalid(), _M_has_value(__x._M_has_value)
+       : _M_has_value(__x._M_has_value)
        {
          if (_M_has_value)
            std::construct_at(__builtin_addressof(_M_val), __x._M_val);
@@ -410,7 +410,7 @@ namespace __expected
        expected(expected<_Up, _Gr>&& __x)
        noexcept(__and_v<is_nothrow_constructible<_Tp, _Up>,
                         is_nothrow_constructible<_Er, _Gr>>)
-       : _M_invalid(), _M_has_value(__x._M_has_value)
+       : _M_has_value(__x._M_has_value)
        {
          if (_M_has_value)
            std::construct_at(__builtin_addressof(_M_val),
@@ -890,7 +890,6 @@ namespace __expected
       }
 
       union {
-       struct { } _M_invalid;
        _Tp _M_val;
        _Er _M_unex;
       };