From patchwork Wed Mar 29 23:39:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 76856 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp758091vqo; Wed, 29 Mar 2023 16:42:16 -0700 (PDT) X-Google-Smtp-Source: AKy350Z3YvQdPiYWTDV24+ZQMQufm5w72g4ROCoxxt57WLAHgbBcZ7wElWx2WpKEvCcXQL0XX2V0 X-Received: by 2002:a17:906:f2d1:b0:932:35b1:47f8 with SMTP id gz17-20020a170906f2d100b0093235b147f8mr21402818ejb.34.1680133336707; Wed, 29 Mar 2023 16:42:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680133336; cv=none; d=google.com; s=arc-20160816; b=bO4C32itdK1ttAunVWuEGvc1Ij9Oyrz4qoaiVu2LoEkDj2wU7jALsZyl6djEavq77E 4iBlMgKqRAannr2wwFH1D4OqMJpsg3l/GgveYki6Jj7zwila2K4VPnw6U1ejbPFPhhbG CzR/0FBeCy1CJTe6sGA2128USKBanNmgJNDUVJ5zgo4qZwrJ9UguEMx3mtlRPcjn4pjt 6b/u9HuPxPkcFxXUhRFcjJ1z71V08TeUR8o/U4S+4Mk375XG+oWjjMzfhRHxaXVhbO7n d6V2HgF3R/cFV/cRrrkJIy2QIkxn88+f2YIFvbUcWv9tTgTqihcaPscvcLdU3c77yg82 1REg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=S+J6cBy+IwCx7ZPya0qTLAuk5D5d5fzJ1Y0wSLILcpU=; b=m4SuOK2g0pRN/SIfUGd8VUrIvsxydWIGLT0srfodZRqHWtJDlhtKDHD0VNn4k1dKse qC/vtaxrER3T0i+5+vlKlwwhDbkrUuF0stAOYAl3FvJPx7/p7GdmN1/8+YIRs4PuyagC 35lm10cBVHsQkLbn6Q26dQ1ZnuqRsAQ3gDpxWUAh6/2I1dHhexx7HGaIHuagzV+Lhfoh QNpXUqc3phy+s3jJNtim3zGW/177ieTmM2ZQiHM5bdRKZqeI18hcLN8hFRYp3iiGE9ig M68rBbuuypfP43+tv+CrTUbERsco9irEKlVv0pLD9JGxIkmSk/n0azJxiiGOfac1w308 vtnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XpZqt4HA; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id t11-20020a170906a10b00b008c8b1a72efcsi29217918ejy.816.2023.03.29.16.42.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 16:42:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XpZqt4HA; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EAE8D385042A for ; Wed, 29 Mar 2023 23:40:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EAE8D385042A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680133236; bh=S+J6cBy+IwCx7ZPya0qTLAuk5D5d5fzJ1Y0wSLILcpU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=XpZqt4HAeyNLSEJmG4ZMSqsO7YY5HMvOSgih5CRudC//zCFnGzgRXyuuzEbI9Il58 k3VXzeFsCZJAE/UKgecGsojpOOdozniDSll/QNBErfecp70aGBKzOiopY8LTdg610J Z5ADssFoT4MWfQnxDGjj4Av2SQfXoKzE3QCRnEtE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 9842A385B51C for ; Wed, 29 Mar 2023 23:39:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9842A385B51C 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) 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 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761747493610058881?= X-GMAIL-MSGID: =?utf-8?q?1761747493610058881?= 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&&