From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1725) id DE2C8386F028; Tue, 18 Aug 2020 18:32:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE2C8386F028 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1597775530; bh=dm5pM5eRsFNBpMEKaHXcVvcU908PMRnqMkz+yZm3+sc=; h=From:To:Subject:Date:From; b=QPU1/U/RvBsvHrceJcgoscSv/92vSfjH3ya9W8W9CogsP/SjzI4PDx/iHMZyAY7Sq L3oQTaZm/mWbk0BUWZmcGudH8AfjbxpZeGUYwsGhSR/prAs/ba2770PgYfAXU6RU8B MU/8xs7TW8f6Pm7BD7QRxZzYAWI/asOnD8Bo5psI= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: William Schmidt To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/users/wschmidt/heads/builtins3)] libstdc++: Replace some VERIFY tests with static_assert X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/users/wschmidt/heads/builtins3 X-Git-Oldrev: 9e4ebad20a064d10df451cfb2cea9853d339a898 X-Git-Newrev: 6c3ae88d1e13b71665d1b27821159dcbea410267 Message-Id: <20200818183210.DE2C8386F028@sourceware.org> Date: Tue, 18 Aug 2020 18:32:10 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Aug 2020 18:32:11 -0000 https://gcc.gnu.org/g:6c3ae88d1e13b71665d1b27821159dcbea410267 commit 6c3ae88d1e13b71665d1b27821159dcbea410267 Author: Jonathan Wakely Date: Fri Aug 7 17:45:42 2020 +0100 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: --- .../comparisons/algorithms/partial_order.cc | 56 +++++++++---------- .../comparisons/algorithms/weak_order.cc | 62 +++++++++++----------- 2 files changed, 61 insertions(+), 57 deletions(-) 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 ); - - 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 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 ); + + 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 );