[libc++] Refactor allocator_mismatch.compile.fail.cpp -> .verify.cpp
authorArthur O'Dwyer <arthur.j.odwyer@gmail.com>
Fri, 20 Jan 2023 19:49:55 +0000 (14:49 -0500)
committerLouis Dionne <ldionne.2@gmail.com>
Tue, 28 Feb 2023 17:22:49 +0000 (12:22 -0500)
compile.fail.cpp tests are an anti-feature since they are too easy to
break when evolving code. This patch moves various allocator_mismatch
tests to .verify.cpp and normalizes the error messages from various
containers.

Differential Revision: https://reviews.llvm.org/D144913

17 files changed:
libcxx/include/forward_list
libcxx/include/list
libcxx/include/unordered_map
libcxx/include/unordered_set
libcxx/test/std/containers/associative/map/allocator_mismatch.verify.cpp [moved from libcxx/test/std/containers/associative/map/allocator_mismatch.compile.fail.cpp with 70% similarity]
libcxx/test/std/containers/associative/multimap/allocator_mismatch.verify.cpp [moved from libcxx/test/std/containers/associative/multimap/allocator_mismatch.compile.fail.cpp with 70% similarity]
libcxx/test/std/containers/associative/multiset/allocator_mismatch.verify.cpp [moved from libcxx/test/std/containers/associative/set/allocator_mismatch.compile.fail.cpp with 70% similarity]
libcxx/test/std/containers/associative/set/allocator_mismatch.verify.cpp [moved from libcxx/test/std/containers/associative/multiset/allocator_mismatch.compile.fail.cpp with 71% similarity]
libcxx/test/std/containers/associative/set/range_concept_conformance.compile.pass.cpp
libcxx/test/std/containers/sequences/deque/allocator_mismatch.verify.cpp [moved from libcxx/test/std/containers/sequences/deque/allocator_mismatch.compile.fail.cpp with 73% similarity]
libcxx/test/std/containers/sequences/forwardlist/allocator_mismatch.verify.cpp [moved from libcxx/test/std/containers/sequences/forwardlist/allocator_mismatch.compile.fail.cpp with 72% similarity]
libcxx/test/std/containers/sequences/list/allocator_mismatch.verify.cpp [moved from libcxx/test/std/containers/sequences/list/allocator_mismatch.compile.fail.cpp with 73% similarity]
libcxx/test/std/containers/sequences/vector/allocator_mismatch.verify.cpp [moved from libcxx/test/std/containers/sequences/vector/allocator_mismatch.compile.fail.cpp with 73% similarity]
libcxx/test/std/containers/unord/unord.map/allocator_mismatch.verify.cpp [moved from libcxx/test/std/containers/unord/unord.map/allocator_mismatch.compile.fail.cpp with 69% similarity]
libcxx/test/std/containers/unord/unord.multimap/allocator_mismatch.verify.cpp [moved from libcxx/test/std/containers/unord/unord.multimap/allocator_mismatch.compile.fail.cpp with 68% similarity]
libcxx/test/std/containers/unord/unord.multiset/allocator_mismatch.verify.cpp [moved from libcxx/test/std/containers/unord/unord.set/allocator_mismatch.compile.fail.cpp with 69% similarity]
libcxx/test/std/containers/unord/unord.set/allocator_mismatch.verify.cpp [moved from libcxx/test/std/containers/unord/unord.multiset/allocator_mismatch.compile.fail.cpp with 69% similarity]

index 43519b5..9276376 100644 (file)
@@ -482,14 +482,6 @@ protected:
     typedef typename allocator_traits<__begin_node_allocator>::pointer
                                                       __begin_node_pointer;
 
-    static_assert((!is_same<allocator_type, __node_allocator>::value),
-                  "internal allocator type must differ from user-specified "
-                  "type; otherwise overload resolution breaks");
-
-    static_assert(is_same<allocator_type, __rebind_alloc<__node_traits, value_type> >::value,
-                  "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
-                  "original allocator");
-
     __compressed_pair<__begin_node, __node_allocator> __before_begin_;
 
     _LIBCPP_INLINE_VISIBILITY
@@ -659,9 +651,17 @@ public:
     typedef _Tp    value_type;
     typedef _Alloc allocator_type;
 
-    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
+    static_assert(is_same<value_type, typename allocator_type::value_type>::value,
                   "Allocator::value_type must be same type as value_type");
 
+    static_assert(is_same<allocator_type, __rebind_alloc<allocator_traits<allocator_type>, value_type> >::value,
+                  "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
+                  "original allocator");
+
+    static_assert((!is_same<allocator_type, __node_allocator>::value),
+                  "internal allocator type must differ from user-specified "
+                  "type; otherwise overload resolution breaks");
+
     typedef value_type&                                                 reference;
     typedef const value_type&                                           const_reference;
     typedef typename allocator_traits<allocator_type>::pointer          pointer;
index c0fe2f9..750ccf9 100644 (file)
@@ -828,7 +828,7 @@ public:
     typedef _Tp                                            value_type;
     typedef _Alloc                                         allocator_type;
     static_assert((is_same<value_type, typename allocator_type::value_type>::value),
-                  "Invalid allocator::value_type");
+                  "Allocator::value_type must be same type as value_type");
     typedef value_type&                                    reference;
     typedef const value_type&                              const_reference;
     typedef typename base::pointer                         pointer;
index af3cad3..251a581 100644 (file)
@@ -1035,7 +1035,7 @@ public:
     typedef value_type&                                    reference;
     typedef const value_type&                              const_reference;
     static_assert((is_same<value_type, typename allocator_type::value_type>::value),
-                  "Invalid allocator::value_type");
+                  "Allocator::value_type must be same type as value_type");
 
 private:
     typedef __hash_value_type<key_type, mapped_type>                          __value_type;
@@ -1928,7 +1928,7 @@ public:
     typedef value_type&                                    reference;
     typedef const value_type&                              const_reference;
     static_assert((is_same<value_type, typename allocator_type::value_type>::value),
-                  "Invalid allocator::value_type");
+                  "Allocator::value_type must be same type as value_type");
 
 private:
     typedef __hash_value_type<key_type, mapped_type>                          __value_type;
index 1c875a5..1fdaf96 100644 (file)
@@ -513,7 +513,7 @@ public:
     typedef value_type&                                                reference;
     typedef const value_type&                                          const_reference;
     static_assert((is_same<value_type, typename allocator_type::value_type>::value),
-                  "Invalid allocator::value_type");
+                  "Allocator::value_type must be same type as value_type");
 
     static_assert(is_same<allocator_type, __rebind_alloc<allocator_traits<allocator_type>, value_type> >::value,
                   "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
@@ -1173,7 +1173,7 @@ public:
     typedef value_type&                                                reference;
     typedef const value_type&                                          const_reference;
     static_assert((is_same<value_type, typename allocator_type::value_type>::value),
-                  "Invalid allocator::value_type");
+                  "Allocator::value_type must be same type as value_type");
 
 private:
     typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
@@ -11,9 +11,5 @@
 
 #include <map>
 
-int main(int, char**)
-{
-    std::map<int, int, std::less<int>, std::allocator<long> > m;
-
-  return 0;
-}
+std::map<int, int, std::less<int>, std::allocator<long> > m;
+  // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed{{.*}}Allocator::value_type must be same type as value_type}}
@@ -11,9 +11,5 @@
 
 #include <map>
 
-int main(int, char**)
-{
-    std::multimap<int, int, std::less<int>, std::allocator<long> > m;
-
-  return 0;
-}
+std::multimap<int, int, std::less<int>, std::allocator<long> > m;
+  // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed{{.*}}Allocator::value_type must be same type as value_type}}
@@ -11,9 +11,5 @@
 
 #include <set>
 
-int main(int, char**)
-{
-    std::set<int, std::less<int>, std::allocator<long> > s;
-
-  return 0;
-}
+std::multiset<int, std::less<int>, std::allocator<long> > m;
+  // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed{{.*}}Allocator::value_type must be same type as value_type}}
@@ -11,9 +11,5 @@
 
 #include <set>
 
-int main(int, char**)
-{
-    std::multiset<int, std::less<int>, std::allocator<long> > ms;
-
-  return 0;
-}
+std::set<int, std::less<int>, std::allocator<long> > m;
+  // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed{{.*}}Allocator::value_type must be same type as value_type}}
index 597abbd..16f4de9 100644 (file)
@@ -32,7 +32,7 @@ static_assert(std::same_as<std::ranges::iterator_t<range const>, range::const_it
 static_assert(std::ranges::bidirectional_range<range const>);
 static_assert(!std::ranges::random_access_range<range const>);
 static_assert(std::ranges::common_range<range const>);
-static_assert(std::ranges::input_range<range>);
+static_assert(std::ranges::input_range<range const>);
 static_assert(!std::ranges::view<range const>);
 static_assert(std::ranges::sized_range<range const>);
 static_assert(!std::ranges::borrowed_range<range const>);
@@ -11,9 +11,5 @@
 
 #include <deque>
 
-int main(int, char**)
-{
-    std::deque<int, std::allocator<long> > d;
-
-  return 0;
-}
+std::deque<int, std::allocator<long> > d;
+  // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed{{.*}}Allocator::value_type must be same type as value_type}}
@@ -11,9 +11,5 @@
 
 #include <forward_list>
 
-int main(int, char**)
-{
-    std::forward_list<int, std::allocator<long> > fl;
-
-  return 0;
-}
+std::forward_list<int, std::allocator<long> > fl;
+  // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed{{.*}}Allocator::value_type must be same type as value_type}}
@@ -11,9 +11,5 @@
 
 #include <list>
 
-int main(int, char**)
-{
-    std::list<int, std::allocator<long> > l;
-
-  return 0;
-}
+std::list<int, std::allocator<long> > l;
+  // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed{{.*}}Allocator::value_type must be same type as value_type}}
@@ -11,9 +11,5 @@
 
 #include <vector>
 
-int main(int, char**)
-{
-    std::vector<int, std::allocator<long> > v;
-
-  return 0;
-}
+std::vector<int, std::allocator<long> > v;
+  // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed{{.*}}Allocator::value_type must be same type as value_type}}
@@ -11,9 +11,5 @@
 
 #include <unordered_map>
 
-int main(int, char**)
-{
-    std::unordered_map<int, int, std::hash<int>, std::less<int>, std::allocator<long> > m;
-
-  return 0;
-}
+std::unordered_map<int, int, std::hash<int>, std::less<int>, std::allocator<long> > m;
+  // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed{{.*}}Allocator::value_type must be same type as value_type}}
@@ -11,9 +11,5 @@
 
 #include <unordered_map>
 
-int main(int, char**)
-{
-    std::unordered_multimap<int, int, std::hash<int>, std::less<int>, std::allocator<long> > m;
-
-  return 0;
-}
+std::unordered_multimap<int, int, std::hash<int>, std::less<int>, std::allocator<long> > m;
+  // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed{{.*}}Allocator::value_type must be same type as value_type}}
@@ -11,9 +11,5 @@
 
 #include <unordered_set>
 
-int main(int, char**)
-{
-    std::unordered_set<int, std::hash<int>, std::less<int>, std::allocator<long> > v;
-
-  return 0;
-}
+std::unordered_multiset<int, std::hash<int>, std::less<int>, std::allocator<long> > v;
+  // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed{{.*}}Allocator::value_type must be same type as value_type}}
@@ -11,9 +11,5 @@
 
 #include <unordered_set>
 
-int main(int, char**)
-{
-    std::unordered_multiset<int, std::hash<int>, std::less<int>, std::allocator<long> > v;
-
-  return 0;
-}
+std::unordered_set<int, std::hash<int>, std::less<int>, std::allocator<long> > v;
+  // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed{{.*}}Allocator::value_type must be same type as value_type}}