From patchwork Tue Mar 3 16:30:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1248499 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-520546-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=yVuUix2S; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SPSoFhJ5; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48X2b45NkKz9sPg for ; Wed, 4 Mar 2020 03:31:44 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=fOIHahIplI2TT+fu dGflLbIQoFDgtZRt6eFJBIkf3UoO1EXGv9B96kMWMatA6kH/4eeMFVLhoZ2jy0t6 zjzNvlafOWj3D0HmCVuYw0NOsC/HfkVnTJT6aj6wons37tGArCd+xedyGZLhh/Z5 m1zSWITRp1Q2BSkYLdVmC9hUxUM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=wqGnpixwRC3x7kstRxPz2B w7PBw=; b=yVuUix2SuDioPoesdH0boYgZ7BuEWdRN/Y1Mz7xUav7ET98Js3U3io qMUOJAsDiBlKQ0frP8G9fZ5zIOwPTSxESI1OzYuOUq6CztkV+dQw2OrEEDvteTEi eekqLITK6bPPcctHewrZybwSoNG5mihLhnML836K55BBE5AsUuYRQ= Received: (qmail 102848 invoked by alias); 3 Mar 2020 16:31:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 102547 invoked by uid 89); 3 Mar 2020 16:30:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Mar 2020 16:30:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583253056; 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=svM4M2XEOOLn7zotdnQjXHoLbZv0t92GjDHbH657cdA=; b=SPSoFhJ5aRBuWmE1mwUhFrAju/HSDUHx/UgDk52eEn02rZaksy6CV3kZJHwGBhyDNbWX9Z uwnRAM4e2PLgug4ZEEBEX2vRaGc7uo/xl7S3mckU5ljNxG5kE/xAWdROJSfczYm3IG0+2K OT60/WhCS3vvIkyj2yomIEcJpX3o+Ho= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-66--tDhq06sNJ2VES5I_uxeGA-1; Tue, 03 Mar 2020 11:30:52 -0500 Received: by mail-qk1-f197.google.com with SMTP id 205so2524906qkg.0 for ; Tue, 03 Mar 2020 08:30:52 -0800 (PST) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id h24sm5412159qkk.3.2020.03.03.08.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 08:30:51 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 1/4] libstdc++: Fix use of is_nothrow_assignable_v in Date: Tue, 3 Mar 2020 11:30:40 -0500 Message-Id: <20200303163043.2182013-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes We are passing a value type as the first argument to is_nothrow_assignable_v, but the result of that is always false. Since this predicate is a part of the condition that guards the corresponding optimizations for these algorithms, this bug means these optimizations are never used. We should be passing a reference type to is_nothrow_assignable_v instead. libstdc++-v3/ChangeLog: * include/bits/ranges_uninitialized.h (uninitialized_copy_fn::operator()): Pass a reference type as the first argument to is_nothrow_assignable_v. (uninitialized_copy_fn::operator()): Likewise. (uninitialized_move_fn::operator()): Likewise. Return an in_out_result with the input iterator stripped of its move_iterator. (uninitialized_move_n_fn::operator()): Likewise. (uninitialized_fill_fn::operator()): Pass a reference type as the first argument to is_nothrow_assignable_v. (uninitialized_fill_n_fn::operator()): Likewise. --- .../include/bits/ranges_uninitialized.h | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/libstdc++-v3/include/bits/ranges_uninitialized.h b/libstdc++-v3/include/bits/ranges_uninitialized.h index 01e1cad646c..f97a07a9b4a 100644 --- a/libstdc++-v3/include/bits/ranges_uninitialized.h +++ b/libstdc++-v3/include/bits/ranges_uninitialized.h @@ -269,7 +269,7 @@ namespace ranges if constexpr (sized_sentinel_for<_ISent, _Iter> && sized_sentinel_for<_OSent, _Out> && is_trivial_v<_OutType> - && is_nothrow_assignable_v<_OutType, + && is_nothrow_assignable_v<_OutType&, iter_reference_t<_Iter>>) { auto __d1 = ranges::distance(__ifirst, __ilast); @@ -316,7 +316,7 @@ namespace ranges using _OutType = remove_reference_t>; if constexpr (sized_sentinel_for<_Sent, _Out> && is_trivial_v<_OutType> - && is_nothrow_assignable_v<_OutType, + && is_nothrow_assignable_v<_OutType&, iter_reference_t<_Iter>>) { auto __d = ranges::distance(__ofirst, __olast); @@ -354,13 +354,15 @@ namespace ranges if constexpr (sized_sentinel_for<_ISent, _Iter> && sized_sentinel_for<_OSent, _Out> && is_trivial_v<_OutType> - && is_nothrow_assignable_v<_OutType, + && is_nothrow_assignable_v<_OutType&, iter_rvalue_reference_t<_Iter>>) { auto __d1 = ranges::distance(__ifirst, __ilast); auto __d2 = ranges::distance(__ofirst, __olast); - return ranges::copy_n(std::make_move_iterator(__ifirst), - std::min(__d1, __d2), __ofirst); + auto [__in, __out] + = ranges::copy_n(std::make_move_iterator(__ifirst), + std::min(__d1, __d2), __ofirst); + return {std::move(__in).base(), __out}; } else { @@ -404,12 +406,14 @@ namespace ranges using _OutType = remove_reference_t>; if constexpr (sized_sentinel_for<_Sent, _Out> && is_trivial_v<_OutType> - && is_nothrow_assignable_v<_OutType, + && is_nothrow_assignable_v<_OutType&, iter_rvalue_reference_t<_Iter>>) { auto __d = ranges::distance(__ofirst, __olast); - return ranges::copy_n(std::make_move_iterator(__ifirst), - std::min(__n, __d), __ofirst); + auto [__in, __out] + = ranges::copy_n(std::make_move_iterator(__ifirst), + std::min(__n, __d), __ofirst); + return {std::move(__in).base(), __out}; } else { @@ -436,7 +440,7 @@ namespace ranges { using _ValueType = remove_reference_t>; if constexpr (is_trivial_v<_ValueType> - && is_nothrow_assignable_v<_ValueType, const _Tp&>) + && is_nothrow_assignable_v<_ValueType&, const _Tp&>) return ranges::fill(__first, __last, __x); else { @@ -469,7 +473,7 @@ namespace ranges { using _ValueType = remove_reference_t>; if constexpr (is_trivial_v<_ValueType> - && is_nothrow_assignable_v<_ValueType, const _Tp&>) + && is_nothrow_assignable_v<_ValueType&, const _Tp&>) return ranges::fill_n(__first, __n, __x); else { From patchwork Tue Mar 3 16:30:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1248496 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-520544-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=LncPVx9e; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=S6Or4ixg; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48X2ZX1BNqz9sPg for ; Wed, 4 Mar 2020 03:31:14 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=fnvghIbfNUeIqLGTSroE+85SwZ0daOUo6gbACa+TtNZQDEJCpq5qa I9DMn7cJVMHSwXIIdCPY7YydGOem2E/f2DGE44nBqPLY0H8qfsxDxXYkYw3JVCYE CFcIFqJd7qbhI+T92vdQG8kl7zkC742Sh5htmiV1cKTOSiJb8S7A5A= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=default; bh=7vLgnNezQwzjfCYZf2xF18DVMoI=; b=LncPVx9ec3Br0Q+0ISEjtAhRwf7u +VurBJ+JvVbrriHFIH7Y7LBAtAk5wX2/Xyzl++ouHVhmZlo3znugRA11XgzqhY07 yao0XKMHlzn5mbOw/ag3vRQE6TZm8HJmEEKWSDa5ijZT6MaahH8rx7h8TuCysBmQ +l8ryzDw535Muv8= Received: (qmail 102574 invoked by alias); 3 Mar 2020 16:31:00 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 102539 invoked by uid 89); 3 Mar 2020 16:30:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=2313, sk:counted X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Mar 2020 16:30:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583253056; 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: in-reply-to:in-reply-to:references:references; bh=LunQfBAiNT66yp9X8bEI9Y6o1Lm0oBdvc0DWLO+kTXs=; b=S6Or4ixgVgtPeYLf9ccz4iKlF4l8y58R5OuG27heb8eQjiste7xIJeJ9g6xOgedj6+B0rw +YrTDv4eKbyq8OObtnWvTSighm94cXhbtoxzpVyAgMHnWatn1Z1mnSMTYSCj/yjU5uqDtJ p6n6PuQ9E6WYMVXzOYTDB6HAGmEyOto= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-210--dM2NdZwMnG3NwS3VKnidg-1; Tue, 03 Mar 2020 11:30:54 -0500 Received: by mail-qt1-f199.google.com with SMTP id f25so2542294qtp.12 for ; Tue, 03 Mar 2020 08:30:54 -0800 (PST) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id h24sm5412159qkk.3.2020.03.03.08.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 08:30:52 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 2/4] libstdc++: Add a move-only testsuite iterator type Date: Tue, 3 Mar 2020 11:30:41 -0500 Message-Id: <20200303163043.2182013-2-ppalka@redhat.com> In-Reply-To: <20200303163043.2182013-1-ppalka@redhat.com> References: <20200303163043.2182013-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes This adds a move-only testsuite iterator type to , which will be used in the tests that verify LWG 3355 and has already seen a need in the tests for LWG 3389 and 3390. libstdc++-v3/ChangeLog: * testsuite/util/testsuite_iterators.h (input_iterator_wrapper_nocopy): New testsuite iterator. * testsuite/24_iterators/counted_iterator/lwg3389.cc: Use it. * testsuite/24_iterators/move_iterator/lwg3390.cc: Likewise. --- .../24_iterators/counted_iterator/lwg3389.cc | 35 ++----------------- .../24_iterators/move_iterator/lwg3390.cc | 35 ++----------------- .../testsuite/util/testsuite_iterators.h | 28 +++++++++++++++ 3 files changed, 32 insertions(+), 66 deletions(-) diff --git a/libstdc++-v3/testsuite/24_iterators/counted_iterator/lwg3389.cc b/libstdc++-v3/testsuite/24_iterators/counted_iterator/lwg3389.cc index cf74fd47bec..8b9bf53f6c5 100644 --- a/libstdc++-v3/testsuite/24_iterators/counted_iterator/lwg3389.cc +++ b/libstdc++-v3/testsuite/24_iterators/counted_iterator/lwg3389.cc @@ -23,44 +23,13 @@ #include using __gnu_test::test_range; -using __gnu_test::input_iterator_wrapper; - -template -struct move_only_wrapper : input_iterator_wrapper -{ - using input_iterator_wrapper::input_iterator_wrapper; - - move_only_wrapper() - : input_iterator_wrapper(nullptr, nullptr) - { } - - move_only_wrapper(const move_only_wrapper&) = delete; - move_only_wrapper& - operator=(const move_only_wrapper&) = delete; - - move_only_wrapper(move_only_wrapper&&) = default; - move_only_wrapper& - operator=(move_only_wrapper&&) = default; - - using input_iterator_wrapper::operator++; - - move_only_wrapper& - operator++() - { - input_iterator_wrapper::operator++(); - return *this; - } -}; - -static_assert(std::input_iterator>); -static_assert(!std::forward_iterator>); -static_assert(!std::copyable>); +using __gnu_test::input_iterator_wrapper_nocopy; // LWG 3389 void test01() { int x[] = {1,2,3,4}; - test_range rx(x); + test_range rx(x); auto it = std::counted_iterator(rx.begin(), 2); } diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3390.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3390.cc index 1df7caccece..7e9f4a0d0cc 100644 --- a/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3390.cc +++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3390.cc @@ -23,44 +23,13 @@ #include using __gnu_test::test_range; -using __gnu_test::input_iterator_wrapper; - -template -struct move_only_wrapper : input_iterator_wrapper -{ - using input_iterator_wrapper::input_iterator_wrapper; - - move_only_wrapper() - : input_iterator_wrapper(nullptr, nullptr) - { } - - move_only_wrapper(const move_only_wrapper&) = delete; - move_only_wrapper& - operator=(const move_only_wrapper&) = delete; - - move_only_wrapper(move_only_wrapper&&) = default; - move_only_wrapper& - operator=(move_only_wrapper&&) = default; - - using input_iterator_wrapper::operator++; - - move_only_wrapper& - operator++() - { - input_iterator_wrapper::operator++(); - return *this; - } -}; - -static_assert(std::input_iterator>); -static_assert(!std::forward_iterator>); -static_assert(!std::copyable>); +using __gnu_test::input_iterator_wrapper_nocopy; // LWG 3390 void test01() { int x[] = {1,2,3,4}; - test_range rx(x); + test_range rx(x); auto it = std::make_move_iterator(rx.begin()); } diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h index 417dff23c50..e47b2b03e40 100644 --- a/libstdc++-v3/testsuite/util/testsuite_iterators.h +++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h @@ -674,6 +674,34 @@ namespace __gnu_test { return iter -= n; } }; + // A move-only input iterator type. + template + struct input_iterator_wrapper_nocopy : input_iterator_wrapper + { + using input_iterator_wrapper::input_iterator_wrapper; + + input_iterator_wrapper_nocopy() + : input_iterator_wrapper(nullptr, nullptr) + { } + + input_iterator_wrapper_nocopy(const input_iterator_wrapper_nocopy&) = delete; + input_iterator_wrapper_nocopy& + operator=(const input_iterator_wrapper_nocopy&) = delete; + + input_iterator_wrapper_nocopy(input_iterator_wrapper_nocopy&&) = default; + input_iterator_wrapper_nocopy& + operator=(input_iterator_wrapper_nocopy&&) = default; + + using input_iterator_wrapper::operator++; + + input_iterator_wrapper_nocopy& + operator++() + { + input_iterator_wrapper::operator++(); + return *this; + } + }; + // A type meeting the minimum std::range requirements template class Iter> class test_range From patchwork Tue Mar 3 16:30:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1248497 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-520545-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=W3+l3Mdu; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MMKWIJtM; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48X2Zk4nHfz9sPg for ; Wed, 4 Mar 2020 03:31:26 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=H9FDu5+GkNHsdgBNBqZeWFl03ZIEnvI8PbSuxF3GJB9siSOzebKmB kQ36nfiwMefxc0fF90YfHmJ3I+CKwaqOtFWyK7iWpq8JPRBGuHjlRcFWOYDkVxjI Ri1VQaD/0HglJOSjTV4tWMVIZfCef6/Y5N15UEkaEqM1hdIMY28sM8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=default; bh=j0OQbUn3CwKh4JblMPxrrLpxyZ4=; b=W3+l3MduFPwv5X8ShZCGcSLdCS88 oSBUhEAgDY82lk9+z1AgRSeNK5F7DSzyJPv1q1SCCgGwdSj8pI4/MomyoWdtJLCD SIW4hnKMWB4I+Byb5ckGKlfWETKEZmeV4B1ESws0RXDcE3Lh8w9Spu+uioHp5OdD OeTWkLBuMcSrbaU= Received: (qmail 102650 invoked by alias); 3 Mar 2020 16:31:00 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 102542 invoked by uid 89); 3 Mar 2020 16:30:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=friend X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Mar 2020 16:30:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583253056; 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: in-reply-to:in-reply-to:references:references; bh=Rne0byjPCE3fbAV31Bp6wZ1xcX48od4ni7rDFX+V+RE=; b=MMKWIJtMJYv0MPvI910TEo86rmtgn6bQSDoc97FCQTQxCX9anh5L+4iZFrRsSZSL2to3N3 wKE1su2hdo++7qrVj5+pxfkSgmvXofnLmsy3aIGL1pYXII5t02SyErRCnYfhZqN3i4Sccn TJkH+bqgu02mDe1/8rB4eiZM6Vee2so= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-134-hB1VsPOqNu6AKsPtVsmN4g-1; Tue, 03 Mar 2020 11:30:55 -0500 Received: by mail-qt1-f198.google.com with SMTP id p12so2555057qtu.6 for ; Tue, 03 Mar 2020 08:30:55 -0800 (PST) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id h24sm5412159qkk.3.2020.03.03.08.30.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 08:30:54 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 3/4] libstdc++: Add a test range type that has a sized sentinel Date: Tue, 3 Mar 2020 11:30:42 -0500 Message-Id: <20200303163043.2182013-3-ppalka@redhat.com> In-Reply-To: <20200303163043.2182013-1-ppalka@redhat.com> References: <20200303163043.2182013-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes This adds a test range type whose end() is a sized sentinel to , which will be used in the tests that verify LWG 3355. libstdc++-v3/ChangeLog: * testsuite/util/testsuite_iterators.h (test_range::get_iterator): Make protected instead of private. (test_sized_range_sized_sent): New. --- .../testsuite/util/testsuite_iterators.h | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h index e47b2b03e40..756940ed092 100644 --- a/libstdc++-v3/testsuite/util/testsuite_iterators.h +++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h @@ -735,6 +735,7 @@ namespace __gnu_test { return i.ptr - s.end; } }; + protected: auto get_iterator(T* p) { @@ -812,6 +813,37 @@ namespace __gnu_test using test_output_sized_range = test_sized_range; + // A type meeting the minimum std::sized_range requirements, and whose end() + // returns a size sentinel. + template class Iter> + struct test_sized_range_sized_sent : test_sized_range + { + using test_sized_range::test_sized_range; + + template + struct sentinel + { + T* end; + + friend bool operator==(const sentinel& s, const I& i) noexcept + { return s.end == i.ptr; } + + friend std::iter_difference_t + operator-(const sentinel& s, const I& i) noexcept + { return s.end - i.ptr; } + + friend std::iter_difference_t + operator-(const I& i, const sentinel& s) noexcept + { return i.ptr - s.end; } + }; + + auto end() & + { + using I = decltype(this->get_iterator(this->bounds.last)); + return sentinel{this->bounds.last}; + } + }; + // test_range and test_sized_range do not own their elements, so they model // std::ranges::borrowed_range. This file does not define specializations of // std::ranges::enable_borrowed_range, so that individual tests can decide From patchwork Tue Mar 3 16:30:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1248500 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-520547-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=pTPa/FJ5; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=LtM1a0+t; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48X2bQ1p2Dz9sRN for ; Wed, 4 Mar 2020 03:32:02 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=VNYXXF6xJAe3oefTxJKAsxHsGo7DKPj+aOaXoF4vkDkYQsU1po9GD Z/IfFHvH2PV+AoATF0UR6fB1KWroODBrgRdpxVIAmuTLj+owcs9aDqVMiwJeAPdu EeKkXUExFTUcgRuzvbf92VgPZV7KLVdVe/ek4VdDBwJicfHjP21e4E= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=default; bh=L2LM/bh1kmfTYXkqwj6PfgtMJFA=; b=pTPa/FJ5j1OcxLI/3UtbHbefoCR7 NMb3E/N3uEyuKdC39biww+Jbfg/Nmo63ApRAXlYAZfmyC1CUzm6/77IUHpy6BKSq dTxW7wp+UM7StAEsD1GMtU8/tWVGHTCs/VPbIa+G+IOE2vZuazf0bkOxY/ACFMn3 LTpLT68N+9Jvk88= Received: (qmail 103082 invoked by alias); 3 Mar 2020 16:31:03 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 102949 invoked by uid 89); 3 Mar 2020 16:31:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Mar 2020 16:31:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583253059; 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: in-reply-to:in-reply-to:references:references; bh=aNLNMksQWTfl8lDPTxpDb0xvXIYsOhdv3mD6d1jPpAs=; b=LtM1a0+tjWhN5Cew3/Oj6ZFf2jBfYVUY+86bHudHAcbSlKYrWtVn2ybUxTilDCutOGrE/d pJ3eJ3ZKNJkivToTwi6tgQnroK1tnGiSfysQoLuWNw0VgB7Gn5LcwUTB9wOSFLmphEBB9g m0xDYOthdbGZuHrmqw8gEAh5/3FcVJM= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-281-LWkM-P1oP4SAt2fUTG7RCw-1; Tue, 03 Mar 2020 11:30:57 -0500 Received: by mail-qk1-f199.google.com with SMTP id z124so2489997qkd.20 for ; Tue, 03 Mar 2020 08:30:57 -0800 (PST) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id h24sm5412159qkk.3.2020.03.03.08.30.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 08:30:55 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 4/4] libstdc++: Move-only input iterator support in algorithms (LWG 3355) Date: Tue, 3 Mar 2020 11:30:43 -0500 Message-Id: <20200303163043.2182013-4-ppalka@redhat.com> In-Reply-To: <20200303163043.2182013-1-ppalka@redhat.com> References: <20200303163043.2182013-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes This adds support for move-only input iterators in the ranges::unitialized_* algorithms defined in , as per LWG 3355. The only changes needed are to add calls to std::move in the appropriate places and to use operator-() instead of ranges::distance() because the latter cannot be used with a move-only iterator with a sized sentinel as is the case here. (This issue with ranges::distance is LWG 3392.) libstdc++-v3/ChangeLog: LWG 3355 The memory algorithms should support move-only input iterators introduced by P1207 * include/bits/ranges_uninitialized.h (__uninitialized_copy_fn::operator()): Use std::move to avoid attempting to copy __ifirst, which could be a move-only input iterator. Use operator- instead of ranges::distance to compute distance from a sized sentinel. (__uninitialized_copy_n_fn::operator()): Likewise. (__uninitialized_move_fn::operator()): Likewise. (__uninitialized_move_n_fn::operator()): Likewise. (__uninitialized_destroy_fn::operator()): Use std::move to avoid attempting to copy __first. (__uninitialized_destroy_n_fn::operator()): Likewise. * testsuite/20_util/specialized_algorithms/destroy/constrained.cc: Augment test. * .../specialized_algorithms/uninitialized_copy/constrained.cc: Likewise. * .../specialized_algorithms/uninitialized_move/constrained.cc: Likewise. --- .../include/bits/ranges_uninitialized.h | 34 ++++++++++--------- .../destroy/constrained.cc | 15 ++++++++ .../uninitialized_copy/constrained.cc | 25 ++++++++++++++ .../uninitialized_move/constrained.cc | 25 ++++++++++++++ 4 files changed, 83 insertions(+), 16 deletions(-) diff --git a/libstdc++-v3/include/bits/ranges_uninitialized.h b/libstdc++-v3/include/bits/ranges_uninitialized.h index f97a07a9b4a..d758078fc03 100644 --- a/libstdc++-v3/include/bits/ranges_uninitialized.h +++ b/libstdc++-v3/include/bits/ranges_uninitialized.h @@ -272,9 +272,10 @@ namespace ranges && is_nothrow_assignable_v<_OutType&, iter_reference_t<_Iter>>) { - auto __d1 = ranges::distance(__ifirst, __ilast); - auto __d2 = ranges::distance(__ofirst, __olast); - return ranges::copy_n(__ifirst, std::min(__d1, __d2), __ofirst); + auto __d1 = __ilast - __ifirst; + auto __d2 = __olast - __ofirst; + return ranges::copy_n(std::move(__ifirst), std::min(__d1, __d2), + __ofirst); } else { @@ -283,7 +284,7 @@ namespace ranges ++__ofirst, (void)++__ifirst) ::new (__detail::__voidify(*__ofirst)) _OutType(*__ifirst); __guard.release(); - return {__ifirst, __ofirst}; + return {std::move(__ifirst), __ofirst}; } } @@ -319,8 +320,9 @@ namespace ranges && is_nothrow_assignable_v<_OutType&, iter_reference_t<_Iter>>) { - auto __d = ranges::distance(__ofirst, __olast); - return ranges::copy_n(__ifirst, std::min(__n, __d), __ofirst); + auto __d = __olast - __ofirst; + return ranges::copy_n(std::move(__ifirst), std::min(__n, __d), + __ofirst); } else { @@ -329,7 +331,7 @@ namespace ranges ++__ofirst, (void)++__ifirst, (void)--__n) ::new (__detail::__voidify(*__ofirst)) _OutType(*__ifirst); __guard.release(); - return {__ifirst, __ofirst}; + return {std::move(__ifirst), __ofirst}; } } }; @@ -357,10 +359,10 @@ namespace ranges && is_nothrow_assignable_v<_OutType&, iter_rvalue_reference_t<_Iter>>) { - auto __d1 = ranges::distance(__ifirst, __ilast); - auto __d2 = ranges::distance(__ofirst, __olast); + auto __d1 = __ilast - __ifirst; + auto __d2 = __olast - __ofirst; auto [__in, __out] - = ranges::copy_n(std::make_move_iterator(__ifirst), + = ranges::copy_n(std::make_move_iterator(std::move(__ifirst)), std::min(__d1, __d2), __ofirst); return {std::move(__in).base(), __out}; } @@ -372,7 +374,7 @@ namespace ranges ::new (__detail::__voidify(*__ofirst)) _OutType(ranges::iter_move(__ifirst)); __guard.release(); - return {__ifirst, __ofirst}; + return {std::move(__ifirst), __ofirst}; } } @@ -409,9 +411,9 @@ namespace ranges && is_nothrow_assignable_v<_OutType&, iter_rvalue_reference_t<_Iter>>) { - auto __d = ranges::distance(__ofirst, __olast); + auto __d = __olast - __ofirst; auto [__in, __out] - = ranges::copy_n(std::make_move_iterator(__ifirst), + = ranges::copy_n(std::make_move_iterator(std::move(__ifirst)), std::min(__n, __d), __ofirst); return {std::move(__in).base(), __out}; } @@ -423,7 +425,7 @@ namespace ranges ::new (__detail::__voidify(*__ofirst)) _OutType(ranges::iter_move(__ifirst)); __guard.release(); - return {__ifirst, __ofirst}; + return {std::move(__ifirst), __ofirst}; } } }; @@ -524,7 +526,7 @@ namespace ranges __destroy_fn::operator()(_Iter __first, _Sent __last) const noexcept { if constexpr (is_trivially_destructible_v>) - return ranges::next(__first, __last); + return ranges::next(std::move(__first), __last); else { for (; __first != __last; ++__first) @@ -549,7 +551,7 @@ namespace ranges operator()(_Iter __first, iter_difference_t<_Iter> __n) const noexcept { if constexpr (is_trivially_destructible_v>) - return ranges::next(__first, __n); + return ranges::next(std::move(__first), __n); else { for (; __n > 0; ++__first, (void)--__n) diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/destroy/constrained.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/destroy/constrained.cc index c04049de0b5..89085d381ed 100644 --- a/libstdc++-v3/testsuite/20_util/specialized_algorithms/destroy/constrained.cc +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/destroy/constrained.cc @@ -29,6 +29,9 @@ #include #include +using __gnu_test::test_range; +using __gnu_test::input_iterator_wrapper_nocopy; + namespace ranges = std::ranges; struct X @@ -69,6 +72,18 @@ test01() } } +void +test02() +{ + // LWG 3355 + { + int x[3] = {0}; + test_range rx(x); + ranges::destroy(rx); + ranges::destroy_n(rx.begin(), 3); + } +} + int main() { diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/constrained.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/constrained.cc index c1a50c45df9..ac5d74558d2 100644 --- a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/constrained.cc +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/constrained.cc @@ -31,6 +31,9 @@ using __gnu_test::test_input_range; using __gnu_test::test_forward_range; +using __gnu_test::test_range; +using __gnu_test::test_sized_range_sized_sent; +using __gnu_test::input_iterator_wrapper_nocopy; namespace ranges = std::ranges; @@ -150,6 +153,28 @@ test02() } } +void +test03() +{ + // LWG 3355 + { + int x[3] = {0}; + int y[3]; + test_sized_range_sized_sent rx(x); + ranges::uninitialized_copy(rx, y); + ranges::uninitialized_copy_n(rx.begin(), 3, y, y+3); + } + + { + int x[3] = {0}; + int y[3]; + test_range rx(x); + test_forward_range ry(y); + ranges::uninitialized_copy(rx, y); + ranges::uninitialized_copy_n(rx.begin(), 3, ry.begin(), ry.end()); + } +} + int main() { diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_move/constrained.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_move/constrained.cc index a7d6fd39b38..6b3544edc55 100644 --- a/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_move/constrained.cc +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_move/constrained.cc @@ -31,6 +31,9 @@ using __gnu_test::test_input_range; using __gnu_test::test_forward_range; +using __gnu_test::test_range; +using __gnu_test::test_sized_range_sized_sent; +using __gnu_test::input_iterator_wrapper_nocopy; namespace ranges = std::ranges; @@ -160,6 +163,28 @@ test02() } } +void +test03() +{ + // LWG 3355 + { + int x[3] = {0}; + int y[3]; + test_sized_range_sized_sent rx(x); + ranges::uninitialized_move(rx, y); + ranges::uninitialized_move_n(rx.begin(), 3, y, y+3); + } + + { + int x[3] = {0}; + int y[3]; + test_range rx(x); + test_forward_range ry(y); + ranges::uninitialized_move(rx, y); + ranges::uninitialized_move_n(rx.begin(), 3, ry.begin(), ry.end()); + } +} + int main() {