From patchwork Mon Feb 24 23:26: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: 1243694 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-520036-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=hhfL7LC8; 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=Bqicd+fW; 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 48RJBC0yLDz9sRQ for ; Tue, 25 Feb 2020 10:27:13 +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=CnPD0Fb4V6kXFXkYsy6nEoaqlNc8vSJaeIz18Xbsji3vXFPv4zE0I 9i5oc6fFzIAXAj1zrwCD/aJVr3+laIWYRqmpz4xOvAwkBAZfbuqfwFlZou03Jwu0 RBXhFTdfFwnJZK3SXDgtmZg3jmge/UmgzTp3yx8Purw/jZaq+JgQ/M= 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=iFXTMjc43y4re9NGjdVZFjaB2pQ=; b=hhfL7LC8254uYGNCcvMXC9LqFVRw MC2XKV5PZQKhsokGFZEXGYC8cbcEp71WAPi/I2r5KrnZRL2FMIW+W07TEd9mcHrK +vkL7HYCsjINj0jot8F/yfXnVye0rExaxuQeIQxUM3dSignPnrVh3Y1eq7BYlkxq XaS/+LWIaK9jcFo= Received: (qmail 113189 invoked by alias); 24 Feb 2020 23:26:57 -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 113162 invoked by uid 89); 24 Feb 2020 23:26:57 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.0 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=HX-Languages-Length:2356, Cat X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Feb 2020 23:26:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582586814; 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=rjr5sAmb+gkp+x16z6vQq7YsZzcNyVLWRu1FqPhmj3s=; b=Bqicd+fWyRUDNaj92Feo4ItXbyyAaRTHq566qcaUaU89Igc7pd2Lm6QaJEomc2vW9QhZxO mty1tyWcXySJzslJsTANiMRQR+vAKhs8fuXlpyhY86Afhn6Sh2kFFlXkfNUi98R3Gkhmqt GGWNBxWj6NJAPg/OcdMT+czQGrqM59o= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-409-nPPSI9X9P5iKMMviM6MHAw-1; Mon, 24 Feb 2020 18:26:52 -0500 Received: by mail-qt1-f200.google.com with SMTP id u40so12568452qtk.1 for ; Mon, 24 Feb 2020 15:26:52 -0800 (PST) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id p126sm6547463qkd.108.2020.02.24.15.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2020 15:26:51 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jwakely@redhat.com, Patrick Palka Subject: [PATCH] libstdc++: LWG 3301 transform_view::iterator has incorrect iterator_category Date: Mon, 24 Feb 2020 18:26:40 -0500 Message-Id: <20200224232643.851356-2-ppalka@redhat.com> In-Reply-To: <20200224232643.851356-1-ppalka@redhat.com> References: <20200224232643.851356-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes libstdc++-v3/ChangeLog: LWG 3301 transform_view::_Iterator has incorrect iterator_category * include/std/ranges (transform_view::_Iterator::_S_iter_cat): Adjust determination of iterator_category as per LWG 3301. * testsuite/std/ranges/adaptors/transform.cc: Augment test. --- libstdc++-v3/include/std/ranges | 16 +++++++++---- .../std/ranges/adaptors/transform.cc | 24 +++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index ab8fbaca38f..aed90e9710e 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -1570,12 +1570,18 @@ namespace views static constexpr auto _S_iter_cat() { - using _Cat - = typename iterator_traits<_Base_iter>::iterator_category; - if constexpr (derived_from<_Cat, contiguous_iterator_tag>) - return random_access_iterator_tag{}; + using _Res = invoke_result_t<_Fp&, range_reference_t<_Base>>; + if constexpr (is_lvalue_reference_v<_Res>) + { + using _Cat + = typename iterator_traits<_Base_iter>::iterator_category; + if constexpr (derived_from<_Cat, contiguous_iterator_tag>) + return random_access_iterator_tag{}; + else + return _Cat{}; + } else - return _Cat{}; + return input_iterator_tag{}; } static constexpr decltype(auto) diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/transform.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/transform.cc index ad51fffb43d..0845febe2cf 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/transform.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/transform.cc @@ -77,10 +77,34 @@ test03() VERIFY( ranges::equal(v, (int[]){1,2,3,4,5}) ); } +void +test04() +{ + // LWG 3302 + { + auto f = [] (int x) { return x; }; + int x[] = {1,2,3,4,5}; + auto v = x | views::transform(f); + auto i = v.begin(); + using Cat = decltype(i)::iterator_category; + static_assert(std::same_as); + } + + { + auto f = [] (int &x) -> int& { return x; }; + int x[] = {1,2,3,4,5}; + auto v = x | views::transform(f); + auto i = v.begin(); + using Cat = decltype(i)::iterator_category; + static_assert(std::derived_from); + } +} + int main() { test01(); test02(); test03(); + test04(); }