From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 54BBC3835836 for ; Tue, 15 Jun 2021 18:53:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 54BBC3835836 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-555-KBv8dv05NsKMb4paihyBXg-1; Tue, 15 Jun 2021 14:53:33 -0400 X-MC-Unique: KBv8dv05NsKMb4paihyBXg-1 Received: by mail-qv1-f70.google.com with SMTP id q8-20020ad45ca80000b02902329fd23199so246134qvh.7 for ; Tue, 15 Jun 2021 11:53:33 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=WRzJwtWUqF/1mfJ5Vp1L/P8tvsmF5Uj7lwl1s3lNYrw=; b=H74O/j2yEaqtyRtPZKcTGMqNYLV9L08VVP2ZhXGcVZzwpmp10i4QYOcNumQh87M/W0 0l9+nv2Vo4+GGTshmZg2RDeGnxp3bM+LfUrWuAoDLHSTcVGhxq2ia7snZMDusy7UGm7l p14wR7XMcmsKbpjOzY/WGXAxoUCV/Sx2MGGFsb25v8RrzFB0/NLPr4JlyMmsW+o3CFAD o/hVYxzV6AmjeSwDNUwaO1ah8PNTej0i1Uyxb8qUm8keKLK4dlMTcVmUbFnxby1IXEV4 JZ8hctfuWolEznPIkE7T8+96UCG1/t93GpUGbk/Pl2OHpn46MKmwR0T9bOatwRn1lYDr yMEQ== X-Gm-Message-State: AOAM533V6FV6xVHOX8Ngy3vRj6MBh4XqHQnr/fAx9QjCN1KiVn1Nyi3M e+SgeHQOrjSPccGXYiaj83lj6GJkJ/DtqwiO0kYrAu3bbh4M7anDonR4PJLwtCRt0aCAP511+Vo 9Zz4TCauP8rvKzvE= X-Received: by 2002:a0c:f1c2:: with SMTP id u2mr6861319qvl.1.1623783213106; Tue, 15 Jun 2021 11:53:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyScAC0fOlnfq2Vwk1s98dQ10kWFqdYipt8Lj64qbT8aBuicXv+cMFZVy3KD1JFF81Wm+bciQ== X-Received: by 2002:a0c:f1c2:: with SMTP id u2mr6861302qvl.1.1623783212794; Tue, 15 Jun 2021 11:53:32 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id o63sm9197644qke.112.2021.06.15.11.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 11:53:32 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 2/1] libstdc++: Non-triv-copyable extra args aren't simple [PR100940] Date: Tue, 15 Jun 2021 14:53:21 -0400 Message-Id: <20210615185321.1082491-1-ppalka@redhat.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890 In-Reply-To: <20210614163543.502297-1-ppalka@redhat.com> References: <20210614163543.502297-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-16.0 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, URI_HEX 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: Tue, 15 Jun 2021 18:53:37 -0000 This force-enables perfect forwarding call wrapper semantics whenever the extra arguments of a partially applied range adaptor aren't all trivially copyable, so as to avoid incurring unnecessary copies of potentially expensive-to-copy objects (such as std::function objects) when invoking the adaptor. Tested on x86_64-pc-linux-gnu, does this look OK for trunk/11? PR libstdc++/100940 libstdc++-v3/ChangeLog: * include/std/ranges (__adaptor::__adaptor_has_simple_extra_args): Also require that the extra arguments are trivially copyable. * testsuite/std/ranges/adaptors/100577.cc (test04): New test. --- libstdc++-v3/include/std/ranges | 6 ++++-- .../testsuite/std/ranges/adaptors/100577.cc | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 856975c6934..e858df88088 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -818,8 +818,10 @@ namespace views::__adaptor // True if the behavior of the range adaptor non-closure _Adaptor is // independent of the value category of its extra arguments _Args. template - concept __adaptor_has_simple_extra_args = _Adaptor::_S_has_simple_extra_args - || _Adaptor::template _S_has_simple_extra_args<_Args...>; + concept __adaptor_has_simple_extra_args + = (_Adaptor::_S_has_simple_extra_args + || _Adaptor::template _S_has_simple_extra_args<_Args...>) + && (is_trivially_copyable_v<_Args> && ...); // A range adaptor closure that represents partial application of // the range adaptor _Adaptor with arguments _Args. diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/100577.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/100577.cc index 8ef084621f9..4040f474ad9 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/100577.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/100577.cc @@ -21,6 +21,7 @@ // PR libstdc++/100577 #include +#include namespace ranges = std::ranges; namespace views = std::ranges::views; @@ -113,4 +114,22 @@ test03() x | std::views::drop(S{}); } +void +test04() +{ + // Non-trivially-copyable extra arguments make a closure not simple. + using F = std::function; + static_assert(!std::is_trivially_copyable_v); + using views::__adaptor::__adaptor_has_simple_extra_args; + using views::__adaptor::__closure_has_simple_call_op; + static_assert(!__adaptor_has_simple_extra_args); + static_assert(!__adaptor_has_simple_extra_args); + static_assert(!__adaptor_has_simple_extra_args); + static_assert(!__adaptor_has_simple_extra_args); + static_assert(!__closure_has_simple_call_op()))>); + static_assert(!__closure_has_simple_call_op()))>); + static_assert(!__closure_has_simple_call_op()))>); + static_assert(!__closure_has_simple_call_op()))>); +} + // { dg-prune-output "in requirements" } -- 2.32.0.93.g670b81a890