libstdc++: Fix tests that use invalid types in ordered containers
authorJonathan Wakely <jwakely@redhat.com>
Fri, 24 Sep 2021 12:21:34 +0000 (13:21 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 28 Sep 2021 19:22:51 +0000 (20:22 +0100)
Types used in ordered containers need to be comparable, or the container
needs to use a custom comparison function. These tests fail when
_GLIBCXX_CONCEPT_CHECKS is defined, because the element types aren't
comparable.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

* testsuite/20_util/is_nothrow_swappable/value.h: Use custom
comparison function for priority_queue of type with no
relational operators.
* testsuite/20_util/is_swappable/value.h: Likewise.
* testsuite/24_iterators/output/concept.cc: Add operator< to
type used in set.

libstdc++-v3/testsuite/20_util/is_nothrow_swappable/value.h
libstdc++-v3/testsuite/20_util/is_swappable/value.h
libstdc++-v3/testsuite/24_iterators/output/concept.cc

index 62b3db8..d6f166b 100644 (file)
@@ -285,7 +285,9 @@ void test01()
   static_assert(test_property<is_nothrow_swappable,
                std::queue<ThrowCopyConsClass>>(true), "");
   static_assert(test_property<is_nothrow_swappable,
-               std::priority_queue<ThrowCopyConsClass>>(true), "");
+               std::priority_queue<ThrowCopyConsClass,
+                                   std::vector<ThrowCopyConsClass>,
+                                   comps::CompareNoThrowCopyable>>(true), "");
   static_assert(test_property<is_nothrow_swappable,
                std::stack<ThrowCopyConsClass>>(true), "");
   static_assert(test_property<is_nothrow_swappable,
index 2f7a00b..eb3f96d 100644 (file)
@@ -55,6 +55,13 @@ namespace funny {
   {
     friend void swap(F3&, F3) {}
   };
+
+  struct DummyCmp
+  {
+    template<class T>
+      bool operator()(const T&, const T&) const
+      { return false; }
+  };
 }
 void test01()
 {
@@ -152,7 +159,9 @@ void test01()
   static_assert(test_property<is_swappable,
                std::priority_queue<int>[1][2][3]>(true), "");
   static_assert(test_property<is_swappable,
-               std::priority_queue<construct::Nontrivial>>(true), "");
+               std::priority_queue<construct::Nontrivial,
+                                   std::vector<construct::Nontrivial>,
+                                   funny::DummyCmp>>(true), "");
   static_assert(test_property<is_swappable,
                std::stack<int>>(true), "");
   static_assert(test_property<is_swappable,
index ddb646b..a052438 100644 (file)
@@ -68,7 +68,7 @@ using std::string;
 using std::string_view;
 using std::vector;
 
-struct B { };
+struct B { bool operator<(const B&) const; };
 
 static_assert( output_iterator< array<int, 1>::iterator, int > );
 static_assert( output_iterator< array<B, 1>::iterator, B > );