public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix tests for std::clamp
@ 2017-09-21 10:06 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2017-09-21 10:06 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 410 bytes --]

The tests using std::greater need to reverse the order of the 'hi' and
'lo' arguments, so that the precondition !comp(hi, lo) is met.

	* testsuite/25_algorithms/clamp/1.cc: Fix order of arguments and
	expected results when using predicate defining reverse order.
	* testsuite/25_algorithms/clamp/constexpr.cc: Likewise.

Tested x86_64-linux with -D_GLIBCXX_ASSERTIONS.

Committing to trunk and gcc-7-branch.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1815 bytes --]

commit f1dabaea28903e55dee8ee52c45edbde766b3bb4
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Sep 21 10:51:45 2017 +0100

    Fix tests for std::clamp
    
            * testsuite/25_algorithms/clamp/1.cc: Fix order of arguments and
            expected results when using predicate defining reverse order.
            * testsuite/25_algorithms/clamp/constexpr.cc: Likewise.

diff --git a/libstdc++-v3/testsuite/25_algorithms/clamp/1.cc b/libstdc++-v3/testsuite/25_algorithms/clamp/1.cc
index 991b10d1fe3..655c241e9a2 100644
--- a/libstdc++-v3/testsuite/25_algorithms/clamp/1.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/clamp/1.cc
@@ -30,12 +30,12 @@ void test01()
   VERIFY( y == 3 );
   VERIFY( z == 4 );
 
-  const int xc = std::clamp(1, 2, 4, std::greater<int>());
-  const int yc = std::clamp(3, 2, 4, std::greater<int>());
-  const int zc = std::clamp(5, 2, 4, std::greater<int>());
-  VERIFY( xc == 4 );
-  VERIFY( yc == 2 );
-  VERIFY( zc == 2 );
+  const int xc = std::clamp(1, 4, 2, std::greater<int>());
+  const int yc = std::clamp(3, 4, 2, std::greater<int>());
+  const int zc = std::clamp(5, 4, 2, std::greater<int>());
+  VERIFY( xc == 2 );
+  VERIFY( yc == 3 );
+  VERIFY( zc == 4 );
 }
 
 int
diff --git a/libstdc++-v3/testsuite/25_algorithms/clamp/constexpr.cc b/libstdc++-v3/testsuite/25_algorithms/clamp/constexpr.cc
index 0864b8e1d30..606748ec689 100644
--- a/libstdc++-v3/testsuite/25_algorithms/clamp/constexpr.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/clamp/constexpr.cc
@@ -27,5 +27,5 @@
 # error "Feature-test macro for clamp has wrong value"
 #endif
 
-static_assert(std::clamp(2, 0, 1) == 1, "");
-static_assert(std::clamp(2, 0, 1, std::greater<int>()) == 0, "");
+static_assert(std::clamp(2, 0, 1) == 1);
+static_assert(std::clamp(2, 1, 0, std::greater<int>()) == 1);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-09-21 10:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-21 10:06 [PATCH] Fix tests for std::clamp Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).