From patchwork Thu Mar 5 16:02:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1249704 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-520719-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=YCxtC+Kx; 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=ZtmhFnQ/; 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 48YFsg24fmz9s3x for ; Fri, 6 Mar 2020 03:03:32 +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=NhsxaQFQNy/Lyjii D7c4sL8rJ2G1fr8Gy5DHoWRcIrUffvKnePVY/ljwZfDpEVMaSQGfdpsw3mZzvZff 5puqDJ3XCIPybGaM20sQWPM+SlF4u/a8SSWCokeJ3z/G7hLtnHhjzyXCgjJya1ix viVka0vm7LLy6rAxkAFNeiZHciE= 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=F0EAzM6dASlPvCJgafTpMI jqreY=; b=YCxtC+KxWNveORh2CrnR6sJeDgpUIn7b5Z+NJhQt/skrUFtff+VMvw EDnjNgw8+Rs4ziP9/BaHUZSFauMMSPrMntMwaWCWZxWlKpff/sEIZ5dqgAZ6PZbV bkM9uL2BoOsUA/l7XjCxAPqVoRHc5aPt9ITd+WjMdp6GpjU3du4A0= Received: (qmail 34383 invoked by alias); 5 Mar 2020 16:03:24 -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 34368 invoked by uid 89); 5 Mar 2020 16:03:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=HX-Languages-Length:3667 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; Thu, 05 Mar 2020 16:03:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583424195; 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=UF4h5WXpZq+JyRxy88E7BoOxhVRu0sGTOgwaAGSeLX0=; b=ZtmhFnQ/+0ZVLlcnhiR1YpG2xa9xLWyolbxptv8JYRZ/BoFWVlkhdoUxtTuUseFtZVOTmy MX0ttseFlDOHITjxIJMe6xWvFTF1uZan13UPrznU+DVNnvjy90Mw/JA/M6VTtRyBbHBOa4 V5Y8oGziq8BdzP1qEa9hAw7mhqSQ39w= 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-411-YENDYt-uPiSeewDXYYHouw-1; Thu, 05 Mar 2020 11:02:59 -0500 Received: by mail-qv1-f70.google.com with SMTP id z39so3299914qve.5 for ; Thu, 05 Mar 2020 08:02:59 -0800 (PST) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id h24sm9024814qkk.3.2020.03.05.08.02.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 08:02:49 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH] libstdc++: Give ranges::empty() a concrete return type (PR 93978) Date: Thu, 5 Mar 2020 11:02:47 -0500 Message-Id: <20200305160247.2705537-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes This works around PR 93978 by avoiding having to instantiate ranges::empty() when checking the constraints of view_interface::operator bool(). When ranges::empty() has an auto return type, then we must instantiate it in order to determine whether the requires expression { ranges::empty(_M_derived()); } is well-formed. But this means instantiating view_interface::empty() and hence view_interface::_M_derived(), all before we've yet deduced the return type of join_view::end(). (The reason view_interface::operator bool() is needed in join_view::end() in the first place is because in this function we perform direct initialization of join_view::_Sentinel from a join_view, and so we try to find a conversion sequence from the latter to the former that goes through this conversion operator.) Giving ranges::empty() a concrete return type of bool should be safe according to [ranges.prim.empty]/4 which says "whenever ranges::empty(E) is a valid expression, it has type bool." This fixes the test case in PR 93978 when compiling without -Wall, but with -Wall the test case still fails due to the issue described in PR c++/94038, I think. I still don't quite understand why the test case doesn't fail without -O. libstdc++-v3/ChangeLog: PR libstdc++/93978 * include/bits/range_access.h (__cust_access::_Empty::operator()): Declare return type to be bool instead of auto. * testsuite/std/ranges/adaptors/93978.cc: New test. --- libstdc++-v3/include/bits/range_access.h | 2 +- .../testsuite/std/ranges/adaptors/93978.cc | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/std/ranges/adaptors/93978.cc diff --git a/libstdc++-v3/include/bits/range_access.h b/libstdc++-v3/include/bits/range_access.h index c814694623c..eab8bb9721b 100644 --- a/libstdc++-v3/include/bits/range_access.h +++ b/libstdc++-v3/include/bits/range_access.h @@ -804,7 +804,7 @@ namespace ranges template requires __member_empty<_Tp> || __size0_empty<_Tp> || __eq_iter_empty<_Tp> - constexpr auto + constexpr bool operator()(_Tp&& __e) const noexcept(_S_noexcept<_Tp>()) { if constexpr (__member_empty<_Tp>) diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/93978.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/93978.cc new file mode 100644 index 00000000000..62b5f5f9dac --- /dev/null +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/93978.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a -O" } +// { dg-do compile { target c++2a } } + +#include +#include + +namespace ranges = std::ranges; +namespace views = std::views; + +void +test() +{ + std::vector x = {""}; + auto i = std::counted_iterator(x.begin(), 1); + auto r = ranges::subrange{i, std::default_sentinel}; + auto v = r | views::join; +}