From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id D45A63857352 for ; Wed, 29 Mar 2023 23:39:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D45A63857352 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680133156; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=S+J6cBy+IwCx7ZPya0qTLAuk5D5d5fzJ1Y0wSLILcpU=; b=d7jeUR5DM1RyrQTSqsOCe2TKfj2CfikTgA4BfIDmumciZvb1rGWGdFPvap5xuAAREp3bix 67vb9wnkM3uApA9MqrfIBJx5waCg2q4vuiMqayO0ClCSXuA6C6MIogGGQBpd8Aliqr+nHh RTwa+LHV8T1cwhArKiw7azMyYLHKe+g= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-433-FP8Ag1qJOH6jAoq471eW8Q-1; Wed, 29 Mar 2023 19:39:15 -0400 X-MC-Unique: FP8Ag1qJOH6jAoq471eW8Q-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C247F185A78B; Wed, 29 Mar 2023 23:39:14 +0000 (UTC) Received: from localhost (unknown [10.33.36.149]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B663492C3E; Wed, 29 Mar 2023 23:39:14 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Apply small fix from LWG 3843 to std::expected Date: Thu, 30 Mar 2023 00:39:14 +0100 Message-Id: <20230329233914.1405196-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested powerpc64le-linux. Pushed to trunk. -- >8 -- 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 | 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&& -- 2.39.2