]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Apply small fix from LWG 3843 to std::expected
authorJonathan Wakely <jwakely@redhat.com>
Wed, 29 Mar 2023 21:43:16 +0000 (22:43 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 29 Mar 2023 23:06:25 +0000 (00:06 +0100)
LWG 3843 adds some type requirements to std::expected::value to ensure
that it can correctly copy the error value if it needs to throw an
exception. We don't need to do anything to enforce that, because it will
already be ill-formed if the type can't be copied. The issue also makes
a small drive-by fix to ensure that a const E& is copied from the
non-const value()& overload, which this change implements.

libstdc++-v3/ChangeLog:

* include/std/expected (expected::value() &): Use const lvalue
for unex member passed to bad_expected_access constructor, as
per LWG 3843.

libstdc++-v3/include/std/expected

index cb5754e2a68be6c4bbd4f3de6b99597a52fac525..058188248bb48e22f6a45db9232492d74b16cc8e 100644 (file)
@@ -736,7 +736,8 @@ namespace __expected
       {
        if (_M_has_value) [[likely]]
          return _M_val;
-       _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(_M_unex));
+       const auto& __unex = _M_unex;
+       _GLIBCXX_THROW_OR_ABORT(bad_expected_access<_Er>(__unex));
       }
 
       constexpr const _Tp&&