From patchwork Thu Nov 9 16:00:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1862139 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=e9JHatm0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SR6C135l9z1yQK for ; Fri, 10 Nov 2023 03:01:33 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 045843856244 for ; Thu, 9 Nov 2023 16:01:29 +0000 (GMT) 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 ESMTPS id EEEEE3858D38 for ; Thu, 9 Nov 2023 16:01:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EEEEE3858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EEEEE3858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699545677; cv=none; b=rNo6lCojnUnEf8eL9sDs1Y/76EDFDdhySIIo9CikqOK2JluaBg8IhA3ZAeGrojV29lhdmIGRltr7zwQAEzF9M1y3hG4X2Fxr9R0QbkmKpmHR7Az9/B9xwuiASex8IWNvt/dXRnCpp6A8W87UXl38JE5cW/T6UVusJDNLz1Bq35o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699545677; c=relaxed/simple; bh=CRsJRwQNt6c+ujlAqoRjLrhPqPz7tqDStkXthgE3vvs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZOAzj+IJ0VhLZ+nprDfRMmPJzE0JXhmQAnB6l5CroVZtY0bKw/rlJDzLrxuJJux+A0Jb1d1fi4qxv/bX9tj9T0ZSVG00hhkXaxKUddbVzHLOool7i7sG76Ht6vL7YnWy9L+jDTZF//PQhkulhfr315ZOaO/ny6HFspeKdGJM3wk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699545674; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hWcFFHI9dfXbYos8OlAhgqeGXESnnIY1gRrRM+TUvgc=; b=e9JHatm0NNjm+NryONCvaojKg57l2JG8r7vg9w+seu7OomswybeU86Ibmvy6Iobyjy3TlO H+9wr6KugLB6FOn6mGBmmDckE0Bj/imh58CEemVmhY2O1JcN/q2fRT10zI1xCFoN+Bz7f/ gH718AggZD7DLMNz4AQ+cp9Dql8J2JM= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-304-i3uPaX5fPrCMmScQwBz9mw-1; Thu, 09 Nov 2023 11:01:13 -0500 X-MC-Unique: i3uPaX5fPrCMmScQwBz9mw-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-41cd638a4beso11919411cf.3 for ; Thu, 09 Nov 2023 08:01:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699545669; x=1700150469; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hWcFFHI9dfXbYos8OlAhgqeGXESnnIY1gRrRM+TUvgc=; b=Ji87Ir7eI8tpKJUx1z9irfhSZmepOvWPOX156F8PhGY2XIKvQ1Adq9mDHdzurIG29z KyUB4ol4frn5mJa6T3TyLj6Q6hfgX4fxkPm4LS6VpyN2/zZmFiONEqTMS83jzuKXBauC rYafikooY7+QzvqcNW4khpd2oRJkOBYOHmw9Z1EQvfDv6ZBYM5fSxUSHhCJs1PmdbMwV Gwa9EwER/UNs3XBh4x9fPg9Y6tFw2P3a28Wp7Jb28obGwNwY1DJw13zS3g5EeXAQgc7u a/v1ubEI6PZnwsN4FKdvK6/oT9hEIwMEmSFts98jr5mDpBcDTydmRH9CbhaQAJLA25hZ pM0Q== X-Gm-Message-State: AOJu0Yy05DADGFUiJu8dGtCjF/c2cWz2x7b0mOue0mbmhF5J+Au4wmEx OwZJZMkoUHha7eh9hR8Ev368KwVa/qPG1MWSkCIiRrxINI/haSwu008qbX2JLfrUuTfxSNacZKE izflfYvB9roW3af7avpgaolYcpZWeBS2aU6+5UEqSLOFdgCfpxGn44lakcVtQ4DobcavzqMmR1n Y= X-Received: by 2002:ac8:5d91:0:b0:41e:7b2b:f339 with SMTP id d17-20020ac85d91000000b0041e7b2bf339mr6993852qtx.26.1699545668780; Thu, 09 Nov 2023 08:01:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHgIf2AeLmQrIs/SUtbH8fR8lFvLCXfYbSLvUQLe+FOPg8xVvEVr83o/MBaZSltw6qp0WNgYg== X-Received: by 2002:ac8:5d91:0:b0:41e:7b2b:f339 with SMTP id d17-20020ac85d91000000b0041e7b2bf339mr6993801qtx.26.1699545668291; Thu, 09 Nov 2023 08:01:08 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id f10-20020ac8134a000000b004108d49f391sm2036097qtj.48.2023.11.09.08.01.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 08:01:07 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH] libstdc++: Fix forwarding in __take/drop_of_repeat_view [PR112453] Date: Thu, 9 Nov 2023 11:00:28 -0500 Message-ID: <20231109160028.2829009-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.rc1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.6 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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested on x86_64-pc-linux-gnu, does this look OK for trunk/13? (The && overloads are also missing on earlier branches, but I don't think it makes a difference there since all uses of that operator* are on lvalues before this fix.) -- >8 -- We need to respect the value category of the repeat_view passed to these two functions when accessing its _M_value member. This revealed that the space-efficient partial specialization of __box lacks && overloads of operator* to match std::optional's API. PR libstdc++/112453 libstdc++-v3/ChangeLog: * include/std/ranges (__detail::__box::operator*): Define && overloads as well. (__detail::__take_of_repeat_view): Forward __r when accessing its _M_value member. (__detail::__drop_of_repeat_view): Likewise. * testsuite/std/ranges/repeat/1.cc (test07): New test. --- libstdc++-v3/include/std/ranges | 20 ++++++++++++++----- libstdc++-v3/testsuite/std/ranges/repeat/1.cc | 13 ++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 7893e3a84c9..41f95dc8f78 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -250,13 +250,21 @@ namespace ranges { return true; }; constexpr _Tp& - operator*() noexcept + operator*() & noexcept { return _M_value; } constexpr const _Tp& - operator*() const noexcept + operator*() const & noexcept { return _M_value; } + constexpr _Tp&& + operator*() && noexcept + { return std::move(_M_value); } + + constexpr const _Tp&& + operator*() const && noexcept + { return std::move(_M_value); } + constexpr _Tp* operator->() noexcept { return std::__addressof(_M_value); } @@ -7799,9 +7807,10 @@ namespace views::__adaptor using _Tp = remove_cvref_t<_Range>; static_assert(__is_repeat_view<_Tp>); if constexpr (sized_range<_Tp>) - return views::repeat(*__r._M_value, std::min(ranges::distance(__r), __n)); + return views::repeat(*std::forward<_Range>(__r)._M_value, + std::min(ranges::distance(__r), __n)); else - return views::repeat(*__r._M_value, __n); + return views::repeat(*std::forward<_Range>(__r)._M_value, __n); } template @@ -7813,7 +7822,8 @@ namespace views::__adaptor if constexpr (sized_range<_Tp>) { auto __sz = ranges::distance(__r); - return views::repeat(*__r._M_value, __sz - std::min(__sz, __n)); + return views::repeat(*std::forward<_Range>(__r)._M_value, + __sz - std::min(__sz, __n)); } else return __r; diff --git a/libstdc++-v3/testsuite/std/ranges/repeat/1.cc b/libstdc++-v3/testsuite/std/ranges/repeat/1.cc index 30636407ee2..9551414e2c8 100644 --- a/libstdc++-v3/testsuite/std/ranges/repeat/1.cc +++ b/libstdc++-v3/testsuite/std/ranges/repeat/1.cc @@ -2,6 +2,7 @@ #include #include +#include #include #if __cpp_lib_ranges_repeat != 202207L @@ -137,6 +138,17 @@ test06() static_assert( requires { views::repeat(move_only{}, 2); } ); } +void +test07() +{ + // PR libstdc++/112453 + auto t = std::views::repeat(std::make_unique(5)) | std::views::take(2); + auto d = std::views::repeat(std::make_unique(5)) | std::views::drop(2); + + auto t2 = std::views::repeat(std::make_unique(5), 4) | std::views::take(2); + auto d2 = std::views::repeat(std::make_unique(5), 4) | std::views::drop(2); +} + int main() { @@ -146,4 +158,5 @@ main() static_assert(test04()); test05(); test06(); + test07(); }