From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id AEA3B38582BD; Wed, 29 Mar 2023 23:38:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AEA3B38582BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680133121; bh=+FHPOuUFuE1oZBl+5oE7wCosAaV+GixrHsFf5Ufd9Tc=; h=From:To:Subject:Date:From; b=HIUmHLN7k/CUKi17LV8f+be3cQ1aQIizRCIcdF3YDeyqLGF4WN2f08stW6ekb3pVQ CStsJOiq1va4xK2ZbSRPsijJ4kAjHMfc1VwoqRWrZ23rwKjYo4zjQsaCG8vDHT5+P7 b4JHgGoZtc5MKdBa0z1pbuFS/RROPCPOfZdrSjdg= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-6935] libstdc++: Apply small fix from LWG 3843 to std::expected X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 31a909712014b75fc6ae2ca5eaa425f218bb5f32 X-Git-Newrev: ce39714a1ce58f2f32e8a44a224061290670db0f Message-Id: <20230329233841.AEA3B38582BD@sourceware.org> Date: Wed, 29 Mar 2023 23:38:41 +0000 (GMT) List-Id: https://gcc.gnu.org/g:ce39714a1ce58f2f32e8a44a224061290670db0f commit r13-6935-gce39714a1ce58f2f32e8a44a224061290670db0f Author: Jonathan Wakely 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. 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 cb5754e2a68..058188248bb 100644 --- a/libstdc++-v3/include/std/expected +++ b/libstdc++-v3/include/std/expected @@ -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&&