From patchwork Mon Jun 14 22:14:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1491880 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=OmN3H31o; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G3m3L2V1cz9sW4 for ; Tue, 15 Jun 2021 08:15:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5BA3B388C00B for ; Mon, 14 Jun 2021 22:15:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5BA3B388C00B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1623708903; bh=plx1+jMr5Rq9g6vDq0Qa68Hxlvrw08W16owqQsQGCY0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=OmN3H31om3pb+US1xbEQ8eGh+oH6EWXAyCmIiG4t0Yy1CRs2XvhSQOV7EguB549P9 UxdQor9BJUx5OXhfPNAVKebAYdpNxEHqvTMGamv1pSAQucbMbEFJyivoXjJxpcWCrI HLiyrkvZCV4qfViA8zb4T+9aURdEnDQqc5quHUeA= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 88C62383543A for ; Mon, 14 Jun 2021 22:14:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 88C62383543A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-545-4jok8mbnP5eM7J5WE5u2ow-1; Mon, 14 Jun 2021 18:14:18 -0400 X-MC-Unique: 4jok8mbnP5eM7J5WE5u2ow-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B6AC100C609; Mon, 14 Jun 2021 22:14:17 +0000 (UTC) Received: from localhost (unknown [10.33.36.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FC2A9808; Mon, 14 Jun 2021 22:14:16 +0000 (UTC) Date: Mon, 14 Jun 2021 23:14:16 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix noexcept-specifier for ranges::empty Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-13.9 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 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: * include/bits/ranges_base.h (ranges::empty): Check whether conversion to bool can throw. * testsuite/std/ranges/access/empty.cc: Check for correct noexcept-specifier. Tested powerpc64le-linux. Committed to trunk. commit f9598d89a9f5a327ecdfa6f6978a0cfbe4447111 Author: Jonathan Wakely Date: Mon Jun 14 22:42:05 2021 libstdc++: Fix noexcept-specifier for ranges::empty Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: * include/bits/ranges_base.h (ranges::empty): Check whether conversion to bool can throw. * testsuite/std/ranges/access/empty.cc: Check for correct noexcept-specifier. diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h index 728d3ad2b25..3bc657ca17e 100644 --- a/libstdc++-v3/include/bits/ranges_base.h +++ b/libstdc++-v3/include/bits/ranges_base.h @@ -476,7 +476,7 @@ namespace ranges _S_noexcept() { if constexpr (__member_empty<_Tp>) - return noexcept(std::declval<_Tp&>().empty()); + return noexcept(bool(std::declval<_Tp&>().empty())); else if constexpr (__size0_empty<_Tp>) return noexcept(_Size{}(std::declval<_Tp&>()) == 0); else diff --git a/libstdc++-v3/testsuite/std/ranges/access/empty.cc b/libstdc++-v3/testsuite/std/ranges/access/empty.cc index 9044dd155da..b2d8b105325 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/empty.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/empty.cc @@ -89,10 +89,41 @@ test03() static_assert( std::ranges::empty(R2{}) ); } +void +test04() +{ + struct E1 + { + bool empty() const noexcept { return {}; } + }; + + static_assert( noexcept(std::ranges::empty(E1{})) ); + + struct E2 + { + bool empty() const noexcept(false) { return {}; } + }; + + static_assert( ! noexcept(std::ranges::empty(E2{})) ); + + struct E3 + { + struct B + { + explicit operator bool() const noexcept(false) { return true; } + }; + + B empty() const noexcept { return {}; } + }; + + static_assert( ! noexcept(std::ranges::empty(E3{})) ); +} + int main() { test01(); test02(); test03(); + test04(); }