Fix warnings in unordered_map
authorEric Fiselier <eric@efcs.ca>
Sun, 19 Jul 2015 03:16:47 +0000 (03:16 +0000)
committerEric Fiselier <eric@efcs.ca>
Sun, 19 Jul 2015 03:16:47 +0000 (03:16 +0000)
llvm-svn: 242634

29 files changed:
libcxx/test/libcxx/test/config.py
libcxx/test/std/containers/unord/unord.map/bucket_count.pass.cpp
libcxx/test/std/containers/unord/unord.map/compare.pass.cpp
libcxx/test/std/containers/unord/unord.map/load_factor.pass.cpp
libcxx/test/std/containers/unord/unord.map/max_bucket_count.pass.cpp
libcxx/test/std/containers/unord/unord.map/max_load_factor.pass.cpp
libcxx/test/std/containers/unord/unord.map/swap_member.pass.cpp
libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/clear.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/clear.pass.cpp with 100% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/emplace.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/emplace.pass.cpp with 100% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/emplace_hint.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/emplace_hint.pass.cpp with 100% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_const_iter.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_const_iter.pass.cpp with 95% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_db1.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_db1.pass.cpp with 100% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_db2.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_db2.pass.cpp with 100% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_iter_db1.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db1.pass.cpp with 100% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_iter_db2.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db2.pass.cpp with 100% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_iter_db3.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db3.pass.cpp with 100% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_iter_db4.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db4.pass.cpp with 100% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_key.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_key.pass.cpp with 97% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_range.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_range.pass.cpp with 100% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_const_lvalue.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_const_lvalue.pass.cpp with 100% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_hint_const_lvalue.pass.cpp with 100% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_rvalue.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_hint_rvalue.pass.cpp with 100% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_init.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_init.pass.cpp with 100% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_or_assign.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_or_assign.pass.cpp with 96% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_range.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_range.pass.cpp with 100% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_rvalue.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_rvalue.pass.cpp with 100% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/try.emplace.pass.cpp [moved from libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/try.emplace.pass.cpp with 97% similarity]
libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp

index 2855ee5..9683099 100644 (file)
@@ -579,6 +579,11 @@ class Configuration(object):
                 self.cxx.addCompileFlagIfSupported('-Wno-pessimizing-move')
                 self.cxx.addCompileFlagIfSupported('-Wno-c++11-extensions')
                 self.cxx.addCompileFlagIfSupported('-Wno-user-defined-literals')
+            std = self.get_lit_conf('std', None)
+            if std in ['c++98', 'c++03']:
+                # The '#define static_assert' provided by libc++ in C++03 mode
+                # causes an unused local typedef whenever it is used.
+                self.cxx.addCompileFlagIfSupported('-Wno-unused-local-typedef')
 
     def configure_sanitizer(self):
         san = self.get_lit_conf('use_sanitizer', '').strip()
index d3e80d8..bc37337 100644 (file)
 #include <string>
 #include <cassert>
 
+#include "test_macros.h"
 #include "min_allocator.h"
 
 int main()
 {
     {
         typedef std::unordered_map<int, std::string> C;
-        typedef C::const_iterator I;
-        typedef std::pair<int, std::string> P;
         const C c;
         assert(c.bucket_count() == 0);
     }
     {
         typedef std::unordered_map<int, std::string> C;
-        typedef C::const_iterator I;
         typedef std::pair<int, std::string> P;
         P a[] =
         {
@@ -48,19 +46,16 @@ int main()
         const C c(std::begin(a), std::end(a));
         assert(c.bucket_count() >= 11);
     }
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
     {
         typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
                             min_allocator<std::pair<const int, std::string>>> C;
-        typedef C::const_iterator I;
-        typedef std::pair<int, std::string> P;
         const C c;
         assert(c.bucket_count() == 0);
     }
     {
         typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
                             min_allocator<std::pair<const int, std::string>>> C;
-        typedef C::const_iterator I;
         typedef std::pair<int, std::string> P;
         P a[] =
         {
index 8979a3a..ea6d02f 100644 (file)
@@ -17,6 +17,7 @@
 // http://llvm.org/bugs/show_bug.cgi?id=16549
 
 #include <unordered_map>
+#include <cassert>
 
 struct Key {
   template <typename T> Key(const T&) {}
@@ -35,8 +36,12 @@ namespace std
 int
 main()
 {
-    std::unordered_map<Key, int>::iterator it =
-        std::unordered_map<Key, int>().find(Key(0));
-    std::pair<std::unordered_map<Key, int>::iterator, bool> result =
-        std::unordered_map<Key, int>().insert(std::make_pair(Key(0), 0));
+    typedef std::unordered_map<Key, int> MapT;
+    typedef MapT::iterator Iter;
+    MapT map;
+    Iter it = map.find(Key(0));
+    assert(it == map.end());
+    std::pair<Iter, bool> result = map.insert(std::make_pair(Key(0), 42));
+    assert(result.second);
+    assert(result.first->second == 42);
 }
index 472e41a..b25c019 100644 (file)
@@ -20,6 +20,7 @@
 #include <cassert>
 #include <cfloat>
 
+#include "test_macros.h"
 #include "min_allocator.h"
 
 int main()
@@ -43,11 +44,10 @@ int main()
     }
     {
         typedef std::unordered_map<int, std::string> C;
-        typedef std::pair<int, std::string> P;
         const C c;
         assert(c.load_factor() == 0);
     }
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
     {
         typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
                             min_allocator<std::pair<const int, std::string>>> C;
@@ -69,7 +69,6 @@ int main()
     {
         typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
                             min_allocator<std::pair<const int, std::string>>> C;
-        typedef std::pair<int, std::string> P;
         const C c;
         assert(c.load_factor() == 0);
     }
index b4ca8eb..08f014d 100644 (file)
 #include <string>
 #include <cassert>
 
+#include "test_macros.h"
 #include "min_allocator.h"
 
 int main()
 {
     {
         typedef std::unordered_map<int, std::string> C;
-        typedef C::const_iterator I;
-        typedef std::pair<int, std::string> P;
         const C c;
         assert(c.max_bucket_count() > 0);
     }
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
     {
         typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
                             min_allocator<std::pair<const int, std::string>>> C;
-        typedef C::const_iterator I;
-        typedef std::pair<int, std::string> P;
         const C c;
         assert(c.max_bucket_count() > 0);
     }
index 69fd70d..b19a6e6 100644 (file)
 // float max_load_factor() const;
 // void max_load_factor(float mlf);
 
-#ifdef _LIBCPP_DEBUG
-#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
-#endif
-
 #include <unordered_map>
 #include <string>
 #include <cassert>
 
+#include "test_macros.h"
 #include "min_allocator.h"
 
 int main()
 {
     {
         typedef std::unordered_map<int, std::string> C;
-        typedef std::pair<int, std::string> P;
         const C c;
         assert(c.max_load_factor() == 1);
     }
     {
         typedef std::unordered_map<int, std::string> C;
-        typedef std::pair<int, std::string> P;
         C c;
         assert(c.max_load_factor() == 1);
         c.max_load_factor(2.5);
         assert(c.max_load_factor() == 2.5);
     }
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
     {
         typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
                             min_allocator<std::pair<const int, std::string>>> C;
-        typedef std::pair<int, std::string> P;
         const C c;
         assert(c.max_load_factor() == 1);
     }
     {
         typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
                             min_allocator<std::pair<const int, std::string>>> C;
-        typedef std::pair<int, std::string> P;
         C c;
         assert(c.max_load_factor() == 1);
         c.max_load_factor(2.5);
index 8ab1eb6..0f98b66 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "../../test_compare.h"
 #include "../../test_hash.h"
+#include "test_macros.h"
 #include "test_allocator.h"
 #include "min_allocator.h"
 
@@ -31,7 +32,6 @@ int main()
         typedef test_compare<std::equal_to<int> > Compare;
         typedef test_allocator<std::pair<const int, std::string> > Alloc;
         typedef std::unordered_map<int, std::string, Hash, Compare, Alloc> C;
-        typedef std::pair<int, std::string> P;
         C c1(0, Hash(1), Compare(1), Alloc(1));
         C c2(0, Hash(2), Compare(2), Alloc(2));
         c2.max_load_factor(2);
@@ -212,7 +212,6 @@ int main()
         typedef test_compare<std::equal_to<int> > Compare;
         typedef other_allocator<std::pair<const int, std::string> > Alloc;
         typedef std::unordered_map<int, std::string, Hash, Compare, Alloc> C;
-        typedef std::pair<int, std::string> P;
         C c1(0, Hash(1), Compare(1), Alloc(1));
         C c2(0, Hash(2), Compare(2), Alloc(2));
         c2.max_load_factor(2);
@@ -387,13 +386,12 @@ int main()
         assert(std::distance(c2.cbegin(), c2.cend()) == c2.size());
         assert(c2.max_load_factor() == 1);
     }
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
     {
         typedef test_hash<std::hash<int> > Hash;
         typedef test_compare<std::equal_to<int> > Compare;
         typedef min_allocator<std::pair<const int, std::string> > Alloc;
         typedef std::unordered_map<int, std::string, Hash, Compare, Alloc> C;
-        typedef std::pair<int, std::string> P;
         C c1(0, Hash(1), Compare(1), Alloc());
         C c2(0, Hash(2), Compare(2), Alloc());
         c2.max_load_factor(2);
index 18e6683..1420204 100644 (file)
@@ -15,6 +15,8 @@
 
 // unordered_map(unordered_map&& u);
 
+// UNSUPPORTED: c++98, c++03
+
 #include <unordered_map>
 #include <string>
 #include <cassert>
 
 int main()
 {
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     {
         typedef std::unordered_map<int, std::string,
                                    test_hash<std::hash<int> >,
                                    test_compare<std::equal_to<int> >,
                                    test_allocator<std::pair<const int, std::string> >
                                    > C;
-        typedef std::pair<int, std::string> P;
-        P a[] =
-        {
-            P(1, "one"),
-            P(2, "two"),
-            P(3, "three"),
-            P(4, "four"),
-            P(1, "four"),
-            P(2, "four"),
-        };
         C c0(7,
             test_hash<std::hash<int> >(8),
             test_compare<std::equal_to<int> >(9),
@@ -105,23 +96,12 @@ int main()
 
         assert(c0.empty());
     }
-#if __cplusplus >= 201103L
     {
         typedef std::unordered_map<int, std::string,
                                    test_hash<std::hash<int> >,
                                    test_compare<std::equal_to<int> >,
                                    min_allocator<std::pair<const int, std::string> >
                                    > C;
-        typedef std::pair<int, std::string> P;
-        P a[] =
-        {
-            P(1, "one"),
-            P(2, "two"),
-            P(3, "three"),
-            P(4, "four"),
-            P(1, "four"),
-            P(2, "four"),
-        };
         C c0(7,
             test_hash<std::hash<int> >(8),
             test_compare<std::equal_to<int> >(9),
@@ -183,7 +163,6 @@ int main()
 
         assert(c0.empty());
     }
-#endif
 #if _LIBCPP_DEBUG >= 1
     {
         std::unordered_map<int, int> s1 = {{1, 1}, {2, 2}, {3, 3}};
@@ -195,5 +174,4 @@ int main()
         assert(s2.size() == 2);
     }
 #endif
-#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 }
@@ -19,6 +19,7 @@
 #include <string>
 #include <cassert>
 
+#include "test_macros.h"
 #include "min_allocator.h"
 
 struct TemplateConstructor
@@ -46,13 +47,13 @@ int main()
         };
         C c(a, a + sizeof(a)/sizeof(a[0]));
         C::const_iterator i = c.find(2);
-        C::iterator j = c.erase(i);
+        c.erase(i);
         assert(c.size() == 3);
         assert(c.at(1) == "one");
         assert(c.at(3) == "three");
         assert(c.at(4) == "four");
     }
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
     {
         typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
                             min_allocator<std::pair<const int, std::string>>> C;
@@ -68,14 +69,14 @@ int main()
         };
         C c(a, a + sizeof(a)/sizeof(a[0]));
         C::const_iterator i = c.find(2);
-        C::iterator j = c.erase(i);
+        c.erase(i);
         assert(c.size() == 3);
         assert(c.at(1) == "one");
         assert(c.at(3) == "three");
         assert(c.at(4) == "four");
     }
 #endif
-#if __cplusplus >= 201402L
+#if TEST_STD_VER >= 14
     {
     //  This is LWG #2059
         typedef TemplateConstructor T;
 #include <string>
 #include <cassert>
 
+#include "test_macros.h"
 #include "min_allocator.h"
 
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
 template <typename Unordered>
 bool only_deletions ( const Unordered &whole, const Unordered &part ) {
     typename Unordered::const_iterator w = whole.begin();
     typename Unordered::const_iterator p = part.begin();
-    
-    while ( w != whole.end () && p != part.end()) {        
+
+    while ( w != whole.end () && p != part.end()) {
         if ( *w == *p )
             p++;
         w++;
@@ -96,7 +97,7 @@ int main()
         assert(c.erase(3) == 0);
         assert(c.size() == 0);
     }
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
     {
         typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
                             min_allocator<std::pair<const int, std::string>>> C;
@@ -161,7 +162,7 @@ int main()
         m[i] = i;
         m2[i] = i;
         }
-    
+
     C::iterator i = m2.begin();
     int ctr = 0;
     while (i != m2.end()) {
@@ -7,7 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// UNSUPPORTED: c++03, c++11, c++14
+// UNSUPPORTED: c++98, c++03, c++11, c++14
 
 // <unordered_map>
 
 // template <class M>
 //  iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj);        // C++17
 
-#include <__config>
 #include <unordered_map>
 #include <cassert>
 #include <tuple>
 
-#include <iostream>
 
 class Moveable
 {
@@ -53,7 +51,7 @@ public:
     bool operator<(const Moveable& x) const
         {return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);}
     size_t hash () const { return std::hash<int>()(int_) + std::hash<double>()(double_); }
-    
+
     int get() const {return int_;}
     bool moved() const {return int_ == -1;}
 };
@@ -66,8 +64,6 @@ namespace std {
 
 int main()
 {
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-#ifndef _LIBCPP_HAS_NO_VARIADICS
 
     { // pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);
         typedef std::unordered_map<int, Moveable> M;
@@ -193,6 +189,4 @@ int main()
         assert(r->second.get() == 5);  // value
     }
 
-#endif  // _LIBCPP_HAS_NO_VARIADICS
-#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 }
\ No newline at end of file
@@ -7,7 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// UNSUPPORTED: c++03, c++11, c++14
+// UNSUPPORTED: c++98, c++03, c++11, c++14
 
 // <unordered_map>
 
@@ -64,8 +64,6 @@ namespace std {
 
 int main()
 {
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-#ifndef _LIBCPP_HAS_NO_VARIADICS
 
     { // pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);
         typedef std::unordered_map<int, Moveable> M;
@@ -110,7 +108,7 @@ int main()
         assert(r.first->second.get() == -1); // value
     }
 
-    {  // pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); 
+    {  // pair<iterator, bool> try_emplace(key_type&& k, Args&&... args);
         typedef std::unordered_map<Moveable, Moveable> M;
         typedef std::pair<M::iterator, bool> R;
         M m;
@@ -146,7 +144,7 @@ int main()
             m.try_emplace ( i, Moveable(i, (double) i));
         assert(m.size() == 10);
         M::const_iterator it = m.find(2);
-        
+
         Moveable mv1(3, 3.0);
         for (int i=0; i < 20; i += 2)
         {
@@ -189,7 +187,4 @@ int main()
         assert(r->first.get()  == 3); // key
         assert(r->second.get() == 4); // value
     }
-
-#endif  // _LIBCPP_HAS_NO_VARIADICS
-#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 }
index 7e04b8d..f3d51f6 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "../../../test_compare.h"
 #include "../../../test_hash.h"
+#include "test_macros.h"
 #include "test_allocator.h"
 #include "min_allocator.h"
 
@@ -31,7 +32,6 @@ int main()
         typedef test_compare<std::equal_to<int> > Compare;
         typedef test_allocator<std::pair<const int, std::string> > Alloc;
         typedef std::unordered_map<int, std::string, Hash, Compare, Alloc> C;
-        typedef std::pair<int, std::string> P;
         C c1(0, Hash(1), Compare(1), Alloc(1));
         C c2(0, Hash(2), Compare(2), Alloc(2));
         c2.max_load_factor(2);
@@ -212,7 +212,6 @@ int main()
         typedef test_compare<std::equal_to<int> > Compare;
         typedef other_allocator<std::pair<const int, std::string> > Alloc;
         typedef std::unordered_map<int, std::string, Hash, Compare, Alloc> C;
-        typedef std::pair<int, std::string> P;
         C c1(0, Hash(1), Compare(1), Alloc(1));
         C c2(0, Hash(2), Compare(2), Alloc(2));
         c2.max_load_factor(2);
@@ -387,13 +386,12 @@ int main()
         assert(std::distance(c2.cbegin(), c2.cend()) == c2.size());
         assert(c2.max_load_factor() == 1);
     }
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
     {
         typedef test_hash<std::hash<int> > Hash;
         typedef test_compare<std::equal_to<int> > Compare;
         typedef min_allocator<std::pair<const int, std::string> > Alloc;
         typedef std::unordered_map<int, std::string, Hash, Compare, Alloc> C;
-        typedef std::pair<int, std::string> P;
         C c1(0, Hash(1), Compare(1), Alloc());
         C c2(0, Hash(2), Compare(2), Alloc());
         c2.max_load_factor(2);