From patchwork Mon May 17 15:43:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1479600 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=FQ+U0cud; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FkNhW6DNyz9sPf for ; Tue, 18 May 2021 01:43:39 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 82CF2389042A; Mon, 17 May 2021 15:43:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 82CF2389042A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1621266215; bh=yivmF3ISvMwa/V6mnZS8bEHxreoZkySuGRV3C/lmm7I=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=FQ+U0cud5pjDAn8m6mcAj6ps5ORBxr9ctzj1vUqf3gVtBv6nL6nKpw5ycE5BxckSX 2Kq5v2lHvXUHejIYHAwEM21BNzznapdoFZFt0Q9dQ8X86h4BivhP9iRysVuUEbfFDy xDq0lcy0WuExcaen809u5+4a6PrkgWDke/jJWvEo= 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.133.124]) by sourceware.org (Postfix) with ESMTP id ED0383890410 for ; Mon, 17 May 2021 15:43:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org ED0383890410 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-28-F6J42D_cPnOpBx4GnuTu2A-1; Mon, 17 May 2021 11:43:30 -0400 X-MC-Unique: F6J42D_cPnOpBx4GnuTu2A-1 Received: by mail-qk1-f198.google.com with SMTP id u9-20020a05620a4549b02902e956c2a3c8so4979544qkp.20 for ; Mon, 17 May 2021 08:43:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yivmF3ISvMwa/V6mnZS8bEHxreoZkySuGRV3C/lmm7I=; b=pplRR9lh/ySIqA2WVhqoNsIAIyBxKlWQz1eoj5lICTOBo8FZTahFZBY6IwJMrIXOtu /OkfSPuuRj59wbDxSQkqDx9s16OiSw/bvSqvuyw0G4LtrwhwH2aMfY6l4fuKUqr1aaE3 TNlGLCVW24Z3R4kQVK+2dp4xpb0PzNdCrjWnGkOIosoe7e9/fLqH2/kIlfN4k9SxUdFy q+aXqUejoj1PZoHg4CMKWWMLcylwqkt4xjxIEGQ2N54XMgkNiZGjsit6zjXq0vxHE5SW ZJxdY1TD9S7wckur2IQr+eQ8KZN/MGOip77giSTxfdhpM8IgYXmzP+IPMiskzq5mJuI1 N2wg== X-Gm-Message-State: AOAM531ln1TGmlCmswZRYt8MXrfUT2Qv64Ub8zH0p+XhuyCRvxaaDfWL TfDiccDNw82l2+kENXGDTZguGLawjsPrLI/ivnFlGsFOWYsddLVE2YV1ORf+eN4sNAkjyVmQ5ne HKxBXDSy4EAiQZRxPc2A4UsEtzhHDQM132wYij7gb9iVO+7c5Y4kbfvGXB4EqyIcs8d4= X-Received: by 2002:ac8:5c02:: with SMTP id i2mr104045qti.159.1621266208960; Mon, 17 May 2021 08:43:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSCHAI999bJbAj1aGt3EzUZ450hhMek5uSlsYfdBg1GU+j2dt6gLH0qT0Pztg7oW3Z6yLWSg== X-Received: by 2002:ac8:5c02:: with SMTP id i2mr104012qti.159.1621266208605; Mon, 17 May 2021 08:43:28 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id c14sm10766476qtc.5.2021.05.17.08.43.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 08:43:28 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Fix up semiregular-box partial specialization [PR100475] Date: Mon, 17 May 2021 11:43:26 -0400 Message-Id: <20210517154326.840680-1-ppalka@redhat.com> X-Mailer: git-send-email 2.31.1.621.g97eea85a0a MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-15.5 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: libstdc++@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This makes the in-place constructor of our partial specialization of __box for already-semiregular types to use direct-non-list-initialization (in accordance with the specification of the primary template), and additionally makes its data() member function use std::__addressof. Tested on x86_64-pc-linux-gnu, does this look OK for 10/11/trunk? libstdc++-v3/ChangeLog: PR libstdc++/100475 * include/std/ranges (__box::__box): Use non-list-initialization in member initializer list of in-place constructor of the partial specialization for semiregular types. (__box::operator->): Use std::__addressof. * testsuite/std/ranges/adaptors/detail/semiregular_box.cc (test02): New test. * testsuite/std/ranges/single_view.cc (test04): New test. --- libstdc++-v3/include/std/ranges | 6 +++--- .../ranges/adaptors/detail/semiregular_box.cc | 18 ++++++++++++++++++ .../testsuite/std/ranges/single_view.cc | 16 ++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 0f69d4f0839..1707aeaebcd 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -163,7 +163,7 @@ namespace ranges constexpr explicit __box(in_place_t, _Args&&... __args) noexcept(is_nothrow_constructible_v<_Tp, _Args...>) - : _M_value{std::forward<_Args>(__args)...} + : _M_value(std::forward<_Args>(__args)...) { } constexpr bool @@ -180,11 +180,11 @@ namespace ranges constexpr _Tp* operator->() noexcept - { return &_M_value; } + { return std::__addressof(_M_value); } constexpr const _Tp* operator->() const noexcept - { return &_M_value; } + { return std::__addressof(_M_value); } }; } // namespace __detail diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/detail/semiregular_box.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/detail/semiregular_box.cc index 65931dea51a..ed694e04fd1 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/detail/semiregular_box.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/detail/semiregular_box.cc @@ -81,3 +81,21 @@ test01() return true; } static_assert(test01()); + +template + struct A { + A() requires make_semiregular; + A(int, int); + A(std::initializer_list) = delete; + }; + +void +test02() +{ + // PR libstdc++/100475 + static_assert(std::semiregular>); + __box> x2(std::in_place, 0, 0); + + static_assert(!std::semiregular>); + __box> x1(std::in_place, 0, 0); +} diff --git a/libstdc++-v3/testsuite/std/ranges/single_view.cc b/libstdc++-v3/testsuite/std/ranges/single_view.cc index 97bc39bb636..f530cc07565 100644 --- a/libstdc++-v3/testsuite/std/ranges/single_view.cc +++ b/libstdc++-v3/testsuite/std/ranges/single_view.cc @@ -58,9 +58,25 @@ test03() VERIFY(*std::ranges::begin(s3) == 'a'); } +void +test04() +{ + // PR libstdc++/100475 + struct A { + A() = default; + A(int, int) { } + A(std::initializer_list) = delete; + void operator&() const = delete; + }; + std::ranges::single_view s(std::in_place, 0, 0); + s.data(); + std::as_const(s).data(); +} + int main() { test01(); test02(); test03(); + test04(); }