From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id 903E0388A41B; Thu, 24 Jun 2021 21:11:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 903E0388A41B Received: by mail-ej1-x62b.google.com with SMTP id bg14so11605065ejb.9; Thu, 24 Jun 2021 14:11:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=E6UL2iPmlMwytdcpkX54NfcVZIfvm2w4+n5l30DVc7U=; b=aKj6OdSh3hvWqvvtfk8FuqDN8o3xrpGT+DPwtjdEHT2alrvuWQfAHpG3V1VtIVlmxB lyE5LqkRhPmRbkIZX4qzWHmNyzJhFToo2BEDjnlfLvpNbtreu+SGQOIRICqnEfVd+3MS 7M8KYy8jIpd+hn7iW50nVimxqOjSHYZoYO/sjmI74JZRBi4RlsWxBlJaxL7lsAc6Dgpw PJS5PsMw0tg97l8760Vwn+BZdCwYcRVSeToa2Y7+bS32hvQy1oDqBqsaC2fMdSXPsfuV SuTKwgrQPc3yzAsHbHRU5IDe6yMHiiUCqx1D8pF5q6x4gPH5Ooei8VGHcC7pkWHWejHi wm1g== X-Gm-Message-State: AOAM531Xc645uIvFlRJ5kPYWkognuzdjiFwgCVJSXtSJnenkI3tcTnw4 sAHM89XDd1nexVl3lWdabN6s7v9iVPT3L3bmMjo= X-Google-Smtp-Source: ABdhPJw3zRoLZHMOH2Pn703r+1F+npW7YfVwOyKsUem7hnl+Urr8JAfoPXtkQByxSgqM2J6i7FinoaL2+XhFJBA4tgE= X-Received: by 2002:a17:906:3042:: with SMTP id d2mr7379488ejd.234.1624569075173; Thu, 24 Jun 2021 14:11:15 -0700 (PDT) MIME-Version: 1.0 References: <82f170be-4968-cae2-f775-c863096b5f@idea> In-Reply-To: <82f170be-4968-cae2-f775-c863096b5f@idea> From: Tim Song Date: Thu, 24 Jun 2021 16:10:39 -0500 Message-ID: Subject: Re: [committed] libstdc++: Implement LWG 2762 for std::unique_ptr::operator* To: Patrick Palka Cc: Jonathan Wakely , "libstdc++" , gcc-patches Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Jun 2021 21:11:19 -0000 That example violates http://eel.is/c++draft/unique.ptr.runtime.general#3 On Thu, Jun 24, 2021 at 1:55 PM Patrick Palka via Gcc-patches wrote: > > On Thu, 24 Jun 2021, Jonathan Wakely via Libstdc++ wrote: > > > The LWG issue proposes to add a conditional noexcept-specifier to > > std::unique_ptr's dereference operator. The issue is currently in > > Tentatively Ready status, but even if it isn't voted into the draft, we > > can do it as a conforming extensions. This commit also adds a similar > > noexcept-specifier to operator[] for the unique_ptr partial > > specialization. > > The conditional noexcept added to unique_ptr::operator[] seems to br= eak > the case where T is complete only after the fact: > > struct T; > extern std::unique_ptr p; > auto& t =3D p[1]; > struct T { }; > > /include/c++/12.0.0/bits/unique_ptr.h: In instantiation of =E2=80=98typen= ame std::add_lvalue_reference<_Tp>::type std::unique_ptr<_Tp [], _Dp>::oper= ator[](std::size_t) co > nst [with _Tp =3D A; _Dp =3D std::default_delete; typename std::add= _lvalue_reference<_Tp>::type =3D A&; std::size_t =3D long unsigned int]=E2= =80=99: > testcase.cc:5:14: required from here > /include/c++/12.0.0/bits/unique_ptr.h:658:48: error: invalid use of incom= plete type =E2=80=98struct A=E2=80=99 > 658 | noexcept(noexcept(std::declval()[std::declval()])) > | ~~~~~~~~~~~~~~~~~~~~~~~^ > testcase.cc:3:8: note: forward declaration of =E2=80=98struct A=E2=80=99 > 3 | struct A; > | ^ > > > > > Also ensure that all dereference operators for shared_ptr are noexcept, > > and adds tests for the std::optional accessors modified by the issue, > > which were already noexcept in our implementation. > > > > Signed-off-by: Jonathan Wakely > > > > libstdc++-v3/ChangeLog: > > > > * include/bits/shared_ptr_base.h (__shared_ptr_access::operator[]= ): > > Add noexcept. > > * include/bits/unique_ptr.h (unique_ptr::operator*): Add > > conditional noexcept as per LWG 2762. > > * testsuite/20_util/shared_ptr/observers/array.cc: Check that > > dereferencing cannot throw. > > * testsuite/20_util/shared_ptr/observers/get.cc: Likewise. > > * testsuite/20_util/optional/observers/lwg2762.cc: New test. > > * testsuite/20_util/unique_ptr/lwg2762.cc: New test. > > > > Tested powerpc64le-linux. Committed to trunk. > > > >