From patchwork Fri Aug 7 16:47:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1342342 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org 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=B5PMhfZ8; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 4BNWVg01xJz9sTR for ; Sat, 8 Aug 2020 02:47:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE17E383E805; Fri, 7 Aug 2020 16:47:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE17E383E805 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596818839; bh=IBYoLvqtARtyfj4KnT8/knuHEtNH+KLu/YW0+sPMMus=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=B5PMhfZ8NJ2cqkyypVn5MUSmIc6MGiJXrO6rF6iB2omB/17kYCoZPh3TyEfcOvp3J 00jwbASP/cSStX4h0D8IF8CU7makkjWX5pkrzfsUOc+l4dzzmqEX725SrUdSwkPnGx 8Wn1eaE4tFc+XXaeLUP0wTSk5fPSd6OJHrtbyGT8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id 8FDE43851C2B for ; Fri, 7 Aug 2020 16:47:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8FDE43851C2B 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-19-uizIIEpbNaubOHVqPhozmQ-1; Fri, 07 Aug 2020 12:47:14 -0400 X-MC-Unique: uizIIEpbNaubOHVqPhozmQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E923918FF665; Fri, 7 Aug 2020 16:47:13 +0000 (UTC) Received: from localhost (unknown [10.33.36.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BC4B5C1C3; Fri, 7 Aug 2020 16:47:13 +0000 (UTC) Date: Fri, 7 Aug 2020 17:47:12 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Replace some VERIFY tests with static_assert Message-ID: <20200807164712.GA2618068@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-14.1 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_NONE, RCVD_IN_MSPIKE_H3, 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@gcc.gnu.org Sender: "Gcc-patches" libstdc++-v3/ChangeLog: * testsuite/18_support/comparisons/algorithms/partial_order.cc: Replace VERIFY with static_assert where the compiler now allows it. * testsuite/18_support/comparisons/algorithms/weak_order.cc: Likewise. Tested x86_64-linux. Committed to trunk. commit 6c3ae88d1e13b71665d1b27821159dcbea410267 Author: Jonathan Wakely Date: Fri Aug 7 17:45:42 2020 libstdc++: Replace some VERIFY tests with static_assert libstdc++-v3/ChangeLog: * testsuite/18_support/comparisons/algorithms/partial_order.cc: Replace VERIFY with static_assert where the compiler now allows it. * testsuite/18_support/comparisons/algorithms/weak_order.cc: Likewise. diff --git a/libstdc++-v3/testsuite/18_support/comparisons/algorithms/partial_order.cc b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/partial_order.cc index 0806eabf74a..62b379a98cb 100644 --- a/libstdc++-v3/testsuite/18_support/comparisons/algorithms/partial_order.cc +++ b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/partial_order.cc @@ -28,11 +28,11 @@ using std::partial_ordering; void test01() { - int one = 1, two = 2; + const int one = 1, two = 2; - VERIFY( partial_order(one, two) == partial_ordering::less ); - VERIFY( partial_order(one, one) == partial_ordering::equivalent ); - VERIFY( partial_order(two, one) == partial_ordering::greater ); + static_assert( partial_order(one, two) == partial_ordering::less ); + static_assert( partial_order(one, one) == partial_ordering::equivalent ); + static_assert( partial_order(two, one) == partial_ordering::greater ); static_assert( noexcept(partial_order(1, 1)) ); } @@ -44,44 +44,45 @@ constexpr partial_ordering different_cv_quals(int i, const int j) void test02() { - int fortytwo = 42, nines = 999, lots = 1000; - VERIFY( different_cv_quals(fortytwo, nines) == partial_ordering::less ); - VERIFY( different_cv_quals(-nines, -nines) == partial_ordering::equivalent ); - VERIFY( different_cv_quals(-nines, -lots) == partial_ordering::greater ); + const int fortytwo = 42, nines = 999, lots = 1000; + static_assert( different_cv_quals(fortytwo, nines) == partial_ordering::less ); + static_assert( different_cv_quals(-nines, -nines) == partial_ordering::equivalent ); + static_assert( different_cv_quals(-nines, -lots) == partial_ordering::greater ); } void test03() { - double zero = 0.0; - VERIFY( partial_order(zero, zero) == partial_ordering::equivalent ); - VERIFY( partial_order(-zero, -zero) == partial_ordering::equivalent ); - VERIFY( partial_order(-zero, zero) == partial_ordering::equivalent ); - VERIFY( partial_order(zero, -zero) == partial_ordering::equivalent ); + constexpr double zero = 0.0; + static_assert( partial_order(zero, zero) == partial_ordering::equivalent ); + static_assert( partial_order(-zero, -zero) == partial_ordering::equivalent ); + static_assert( partial_order(-zero, zero) == partial_ordering::equivalent ); + static_assert( partial_order(zero, -zero) == partial_ordering::equivalent ); static_assert( noexcept(partial_order(zero, 1.0)) ); static_assert( partial_order(0.0, 1.0) == std::partial_ordering::less ); - double min = std::numeric_limits::lowest(); - double max = std::numeric_limits::max(); - double nan = std::numeric_limits::quiet_NaN(); - double inf = std::numeric_limits::infinity(); - double denorm = std::numeric_limits::denorm_min(); - double smallest = std::numeric_limits::min(); - double epsilon = std::numeric_limits::epsilon(); - VERIFY( partial_order(denorm, smallest) == partial_ordering::less ); - VERIFY( partial_order(denorm, 0.0) == partial_ordering::greater ); + constexpr double min = std::numeric_limits::lowest(); + constexpr double max = std::numeric_limits::max(); + constexpr double nan = std::numeric_limits::quiet_NaN(); + constexpr double inf = std::numeric_limits::infinity(); + constexpr double denorm = std::numeric_limits::denorm_min(); + constexpr double smallest = std::numeric_limits::min(); + constexpr double epsilon = std::numeric_limits::epsilon(); + static_assert( partial_order(denorm, smallest) == partial_ordering::less ); + static_assert( partial_order(denorm, 0.0) == partial_ordering::greater ); + // FIXME: these should all use static_assert VERIFY( partial_order(0.0, nan) == partial_ordering::unordered ); VERIFY( partial_order(nan, nan) == partial_ordering::unordered ); VERIFY( partial_order(nan, 0.0) == partial_ordering::unordered ); VERIFY( partial_order(-nan, 0.0) == partial_ordering::unordered ); VERIFY( partial_order(-nan, min) == partial_ordering::unordered ); - VERIFY( partial_order(-inf, min) == partial_ordering::less ); + static_assert( partial_order(-inf, min) == partial_ordering::less ); VERIFY( partial_order(-nan, -inf) == partial_ordering::unordered ); VERIFY( partial_order(-inf, -nan) == partial_ordering::unordered ); - VERIFY( partial_order(max, inf) == partial_ordering::less ); - VERIFY( partial_order(inf, max) == partial_ordering::greater ); - VERIFY( partial_order(inf, nan) == partial_ordering::unordered ); - VERIFY( partial_order(1.0, 1.0+epsilon) == partial_ordering::less ); + static_assert( partial_order(max, inf) == partial_ordering::less ); + static_assert( partial_order(inf, max) == partial_ordering::greater ); + static_assert( partial_order(inf, nan) == partial_ordering::unordered ); + static_assert( partial_order(1.0, 1.0+epsilon) == partial_ordering::less ); } namespace N @@ -107,6 +108,7 @@ test04() X one{1}; X negone{-1}; + // FIXME: these should all use static_assert VERIFY( partial_order(one, X{1}) == partial_ordering::equivalent ); VERIFY( partial_order(negone, X{-2}) == partial_ordering::equivalent ); VERIFY( partial_order(one, X{2}) == partial_ordering::greater ); diff --git a/libstdc++-v3/testsuite/18_support/comparisons/algorithms/weak_order.cc b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/weak_order.cc index d7d43ade8d2..f417f562389 100644 --- a/libstdc++-v3/testsuite/18_support/comparisons/algorithms/weak_order.cc +++ b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/weak_order.cc @@ -28,11 +28,11 @@ using std::weak_ordering; void test01() { - int one = 1, two = 2; + const int one = 1, two = 2; - VERIFY( weak_order(one, two) == weak_ordering::less ); - VERIFY( weak_order(one, one) == weak_ordering::equivalent ); - VERIFY( weak_order(two, one) == weak_ordering::greater ); + static_assert( weak_order(one, two) == weak_ordering::less ); + static_assert( weak_order(one, one) == weak_ordering::equivalent ); + static_assert( weak_order(two, one) == weak_ordering::greater ); static_assert( noexcept(weak_order(1, 1)) ); } @@ -44,45 +44,46 @@ constexpr weak_ordering different_cv_quals(int i, const int j) void test02() { - int fortytwo = 42, nines = 999, lots = 1000; + const int fortytwo = 42, nines = 999, lots = 1000; - VERIFY( different_cv_quals(fortytwo, nines) == weak_ordering::less ); - VERIFY( different_cv_quals(-nines, -nines) == weak_ordering::equivalent ); - VERIFY( different_cv_quals(-nines, -lots) == weak_ordering::greater ); + static_assert( different_cv_quals(fortytwo, nines) == weak_ordering::less ); + static_assert( different_cv_quals(-nines, -nines) == weak_ordering::equivalent ); + static_assert( different_cv_quals(-nines, -lots) == weak_ordering::greater ); } void test03() { - double zero = 0.0; - VERIFY( weak_order(zero, zero) == weak_ordering::equivalent ); - VERIFY( weak_order(-zero, -zero) == weak_ordering::equivalent ); - VERIFY( weak_order(-zero, zero) == weak_ordering::equivalent ); - VERIFY( weak_order(zero, -zero) == weak_ordering::equivalent ); + constexpr double zero = 0.0; + static_assert( weak_order(zero, zero) == weak_ordering::equivalent ); + static_assert( weak_order(-zero, -zero) == weak_ordering::equivalent ); + static_assert( weak_order(-zero, zero) == weak_ordering::equivalent ); + static_assert( weak_order(zero, -zero) == weak_ordering::equivalent ); - double min = std::numeric_limits::lowest(); - double max = std::numeric_limits::max(); - double nan = std::numeric_limits::quiet_NaN(); - double inf = std::numeric_limits::infinity(); - double denorm = std::numeric_limits::denorm_min(); - double smallest = std::numeric_limits::min(); - double epsilon = std::numeric_limits::epsilon(); - VERIFY( weak_order(denorm, smallest) == weak_ordering::less ); - VERIFY( weak_order(denorm, 0.0) == weak_ordering::greater ); + constexpr double min = std::numeric_limits::lowest(); + constexpr double max = std::numeric_limits::max(); + constexpr double nan = std::numeric_limits::quiet_NaN(); + constexpr double inf = std::numeric_limits::infinity(); + constexpr double denorm = std::numeric_limits::denorm_min(); + constexpr double smallest = std::numeric_limits::min(); + constexpr double epsilon = std::numeric_limits::epsilon(); + static_assert( weak_order(denorm, smallest) == weak_ordering::less ); + static_assert( weak_order(denorm, 0.0) == weak_ordering::greater ); + // FIXME: these should all use static_assert VERIFY( weak_order(0.0, nan) == weak_ordering::less ); - VERIFY( weak_order(nan, nan) == weak_ordering::equivalent ); - VERIFY( weak_order(nan, -nan) == weak_ordering::greater ); - VERIFY( weak_order(-nan, nan) == weak_ordering::less ); + static_assert( weak_order(nan, nan) == weak_ordering::equivalent ); + static_assert( weak_order(nan, -nan) == weak_ordering::greater ); + static_assert( weak_order(-nan, nan) == weak_ordering::less ); VERIFY( weak_order(nan, 0.0) == weak_ordering::greater ); VERIFY( weak_order(-nan, 0.0) == weak_ordering::less ); VERIFY( weak_order(-nan, min) == weak_ordering::less ); - VERIFY( weak_order(-inf, min) == weak_ordering::less ); + static_assert( weak_order(-inf, min) == weak_ordering::less ); VERIFY( weak_order(-nan, -inf) == weak_ordering::less ); VERIFY( weak_order(-inf, -nan) == weak_ordering::greater ); - VERIFY( weak_order(max, inf) == weak_ordering::less ); - VERIFY( weak_order(inf, max) == weak_ordering::greater ); + static_assert( weak_order(max, inf) == weak_ordering::less ); + static_assert( weak_order(inf, max) == weak_ordering::greater ); VERIFY( weak_order(inf, nan) == weak_ordering::less ); - VERIFY( weak_order(1.0, 1.0+epsilon) == weak_ordering::less ); + static_assert( weak_order(1.0, 1.0+epsilon) == weak_ordering::less ); } namespace N @@ -108,6 +109,7 @@ test04() X one{1}; X negone{-1}; + // FIXME: these should all use static_assert VERIFY( weak_order(one, X{1}) == weak_ordering::equivalent ); VERIFY( weak_order(negone, X{-2}) == weak_ordering::equivalent ); VERIFY( weak_order(one, X{2}) == weak_ordering::greater );