public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-9451] libstdc++: Apply small fix from LWG 3843 to std::expected
@ 2023-04-20 13:57 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-04-20 13:57 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:21e5ee580b553a0aa28bae8c7463a9c5a8e7a646

commit r12-9451-g21e5ee580b553a0aa28bae8c7463a9c5a8e7a646
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Mar 29 22:43:16 2023 +0100

    libstdc++: Apply small fix from LWG 3843 to std::expected
    
    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.
    
    (cherry picked from commit ce39714a1ce58f2f32e8a44a224061290670db0f)

Diff:
---
 libstdc++-v3/include/std/expected | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/expected b/libstdc++-v3/include/std/expected
index 3b97b7b59d8..ed123fb9b59 100644
--- a/libstdc++-v3/include/std/expected
+++ b/libstdc++-v3/include/std/expected
@@ -714,7 +714,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&&

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-20 13:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-20 13:57 [gcc r12-9451] libstdc++: Apply small fix from LWG 3843 to std::expected Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).