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 8730F384842C for ; Mon, 14 Jun 2021 22:14:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8730F384842C 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 From: Jonathan Wakely 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-Type: multipart/mixed; boundary="mfRnmZZ7oC2Ledso" 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=unavailable 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: Mon, 14 Jun 2021 22:14:23 -0000 --mfRnmZZ7oC2Ledso Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. --mfRnmZZ7oC2Ledso Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" 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(); } --mfRnmZZ7oC2Ledso--