[libcxx-commits] [libcxx] f42355e - [libc++] [test] Test that unordered_*::swap/move/assign does not invalidate iterators.
Arthur O'Dwyer via libcxx-commits
libcxx-commits at lists.llvm.org
Fri May 7 07:05:28 PDT 2021
Author: Arthur O'Dwyer
Date: 2021-05-07T10:04:26-04:00
New Revision: f42355e17c3f3d1d099d028a388796a64724ffdb
URL: https://github.com/llvm/llvm-project/commit/f42355e17c3f3d1d099d028a388796a64724ffdb
DIFF: https://github.com/llvm/llvm-project/commit/f42355e17c3f3d1d099d028a388796a64724ffdb.diff
LOG: [libc++] [test] Test that unordered_*::swap/move/assign does not invalidate iterators.
And remove the dedicated debug-iterator tests; we want to test this in all modes.
We have a CI step for testing the whole test suite with `--debug_level=1` now.
Part of https://reviews.llvm.org/D102003
Added:
Modified:
libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.pass.cpp
libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp
libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp
libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp
libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp
libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_non_member.pass.cpp
libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp
libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move.pass.cpp
libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_non_member.pass.cpp
libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_move.pass.cpp
libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move.pass.cpp
libcxx/test/std/containers/unord/unord.set/unord.set.swap/swap_non_member.pass.cpp
Removed:
libcxx/test/libcxx/containers/unord/unord.map/db_move.pass.cpp
libcxx/test/libcxx/containers/unord/unord.multimap/db_move.pass.cpp
libcxx/test/libcxx/containers/unord/unord.multiset/db_move.pass.cpp
libcxx/test/libcxx/containers/unord/unord.set/db_move.pass.cpp
################################################################################
diff --git a/libcxx/test/libcxx/containers/unord/unord.map/db_move.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.map/db_move.pass.cpp
deleted file mode 100644
index 5f18cb3945a54..0000000000000
--- a/libcxx/test/libcxx/containers/unord/unord.map/db_move.pass.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <unordered_map>
-
-// unordered_map(unordered_map&& u);
-
-// UNSUPPORTED: c++03
-// UNSUPPORTED: libcxx-no-debug-mode
-
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
-#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
-
-#include <unordered_map>
-#include <cassert>
-#include <utility>
-
-#include "test_macros.h"
-
-int main(int, char**) {
- std::unordered_map<int, int> s1 = {{1, 1}, {2, 2}, {3, 3}};
- std::unordered_map<int, int>::iterator i = s1.begin();
- std::pair<const int, int> k = *i;
- std::unordered_map<int, int> s2 = std::move(s1);
- assert(*i == k);
- s2.erase(i);
- assert(s2.size() == 2);
-
- return 0;
-}
diff --git a/libcxx/test/libcxx/containers/unord/unord.multimap/db_move.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.multimap/db_move.pass.cpp
deleted file mode 100644
index 0aff618b3c597..0000000000000
--- a/libcxx/test/libcxx/containers/unord/unord.multimap/db_move.pass.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++03
-
-// <unordered_map>
-
-// unordered_multimap(unordered_multimap&& u);
-
-// UNSUPPORTED: libcxx-no-debug-mode
-
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
-#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
-
-#include <unordered_map>
-#include <cassert>
-#include <utility>
-
-#include "test_macros.h"
-
-int main(int, char**) {
- std::unordered_multimap<int, int> s1 = {{1, 1}, {2, 2}, {3, 3}};
- std::unordered_multimap<int, int>::iterator i = s1.begin();
- std::pair<const int, int> k = *i;
- std::unordered_multimap<int, int> s2 = std::move(s1);
- assert(*i == k);
- s2.erase(i);
- assert(s2.size() == 2);
-
- return 0;
-}
diff --git a/libcxx/test/libcxx/containers/unord/unord.multiset/db_move.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.multiset/db_move.pass.cpp
deleted file mode 100644
index 6e89ff29c6d94..0000000000000
--- a/libcxx/test/libcxx/containers/unord/unord.multiset/db_move.pass.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++03
-
-// <unordered_set>
-
-// unordered_multiset(unordered_multiset&& u);
-
-// UNSUPPORTED: libcxx-no-debug-mode
-
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
-#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
-
-#include <unordered_set>
-#include <cassert>
-#include <utility>
-
-#include "test_macros.h"
-
-int main(int, char**) {
- std::unordered_multiset<int> s1 = {1, 2, 3};
- std::unordered_multiset<int>::iterator i = s1.begin();
- int k = *i;
- std::unordered_multiset<int> s2 = std::move(s1);
- assert(*i == k);
- s2.erase(i);
- assert(s2.size() == 2);
-
- return 0;
-}
diff --git a/libcxx/test/libcxx/containers/unord/unord.set/db_move.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.set/db_move.pass.cpp
deleted file mode 100644
index ba7c095a05d09..0000000000000
--- a/libcxx/test/libcxx/containers/unord/unord.set/db_move.pass.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++03
-// UNSUPPORTED: libcxx-no-debug-mode
-
-// <unordered_set>
-
-// unordered_set(unordered_set&& u);
-
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
-#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
-
-#include <unordered_set>
-#include <cassert>
-#include <utility>
-
-#include "test_macros.h"
-
-int main(int, char**) {
- std::unordered_set<int> s1 = {1, 2, 3};
- std::unordered_set<int>::iterator i = s1.begin();
- int k = *i;
- std::unordered_set<int> s2 = std::move(s1);
- assert(*i == k);
- s2.erase(i);
- assert(s2.size() == 2);
-
- return 0;
-}
diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.pass.cpp
index ceb7a0227244b..2378a5d4aad87 100644
--- a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.pass.cpp
@@ -105,6 +105,7 @@ int main(int, char**)
test_compare<std::equal_to<int> >(3),
A(10)
);
+ C::iterator it0 = c0.begin();
c = std::move(c0);
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 4);
@@ -121,6 +122,7 @@ int main(int, char**)
assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
assert(c.max_load_factor() == 1);
assert(c0.size() == 0);
+ assert(it0 == c.begin()); // Iterators remain valid
}
{
typedef other_allocator<std::pair<const int, std::string> > A;
@@ -151,6 +153,7 @@ int main(int, char**)
test_compare<std::equal_to<int> >(3),
A(4)
);
+ C::iterator it0 = c0.begin();
c = std::move(c0);
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 4);
@@ -167,6 +170,7 @@ int main(int, char**)
assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
assert(c.max_load_factor() == 1);
assert(c0.size() == 0);
+ assert(it0 == c.begin()); // Iterators remain valid
}
{
typedef min_allocator<std::pair<const int, std::string> > A;
@@ -197,6 +201,7 @@ int main(int, char**)
test_compare<std::equal_to<int> >(3),
A()
);
+ C::iterator it0 = c0.begin();
c = std::move(c0);
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 4);
@@ -213,6 +218,7 @@ int main(int, char**)
assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
assert(c.max_load_factor() == 1);
assert(c0.size() == 0);
+ assert(it0 == c.begin()); // Iterators remain valid
}
return 0;
diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp
index 6efaa63eeb4ef..363f2f818f160 100644
--- a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp
@@ -42,6 +42,7 @@ int main(int, char**)
test_compare<std::equal_to<int> >(9),
test_allocator<std::pair<const int, std::string> >(10)
);
+ C::iterator it0 = c0.begin();
C c = std::move(c0);
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 0);
@@ -54,6 +55,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
assert(c.load_factor() == 0);
assert(c.max_load_factor() == 1);
+ assert(it0 == c.begin()); // Iterators remain valid
assert(c0.empty());
}
@@ -79,6 +81,7 @@ int main(int, char**)
test_compare<std::equal_to<int> >(9),
test_allocator<std::pair<const int, std::string> >(10)
);
+ C::iterator it0 = c0.begin();
C c = std::move(c0);
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 4);
@@ -95,6 +98,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
assert(c.max_load_factor() == 1);
+ assert(it0 == c.begin()); // Iterators remain valid
assert(c0.empty());
}
@@ -109,6 +113,7 @@ int main(int, char**)
test_compare<std::equal_to<int> >(9),
min_allocator<std::pair<const int, std::string> >()
);
+ C::iterator it0 = c0.begin();
C c = std::move(c0);
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 0);
@@ -121,6 +126,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
assert(c.load_factor() == 0);
assert(c.max_load_factor() == 1);
+ assert(it0 == c.begin()); // Iterators remain valid
assert(c0.empty());
}
@@ -146,6 +152,7 @@ int main(int, char**)
test_compare<std::equal_to<int> >(9),
min_allocator<std::pair<const int, std::string> >()
);
+ C::iterator it0 = c0.begin();
C c = std::move(c0);
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 4);
@@ -162,6 +169,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
assert(c.max_load_factor() == 1);
+ assert(it0 == c.begin()); // Iterators remain valid
assert(c0.empty());
}
diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp
index 7852394cdfbb8..d145c74ecc1c6 100644
--- a/libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp
@@ -75,6 +75,7 @@ int main(int, char**)
C c1(0, Hash(1), Compare(1), Alloc(1, 1));
C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
c2.max_load_factor(2);
+ C::iterator it2 = c2.begin();
swap(c1, c2);
assert(c1.bucket_count() >= 8);
@@ -93,6 +94,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
assert(c1.max_load_factor() == 2);
+ assert(it2 == c1.begin()); // Iterators are not invalidated
LIBCPP_ASSERT(c2.bucket_count() == 0);
assert(c2.size() == 0);
@@ -121,6 +123,7 @@ int main(int, char**)
C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
C c2(0, Hash(2), Compare(2), Alloc(1, 2));
c2.max_load_factor(2);
+ C::iterator it1 = c1.begin();
swap(c1, c2);
LIBCPP_ASSERT(c1.bucket_count() == 0);
@@ -144,6 +147,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
assert(c2.max_load_factor() == 1);
+ assert(it1 == c2.begin()); // Iterators are not invalidated
}
{
typedef test_hash<std::hash<int> > Hash;
@@ -174,6 +178,8 @@ int main(int, char**)
C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
c2.max_load_factor(2);
+ C::iterator it1 = c1.begin();
+ C::iterator it2 = c2.begin();
swap(c1, c2);
assert(c1.bucket_count() >= 8);
@@ -192,6 +198,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
assert(c1.max_load_factor() == 2);
+ assert(it2 == c1.begin()); // Iterators are not invalidated
assert(c2.bucket_count() >= 4);
assert(c2.size() == 4);
@@ -205,6 +212,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
assert(c2.max_load_factor() == 1);
+ assert(it1 == c2.begin()); // Iterators are not invalidated
}
{
diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp
index dfc64bdffb1ee..e163d0a20ba94 100644
--- a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp
@@ -122,7 +122,9 @@ int main(int, char**)
test_compare<std::equal_to<int> >(3),
A(10)
);
+ C::iterator it0 = c0.begin();
c = std::move(c0);
+ assert(it0 == c.begin()); // Iterators remain valid
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 6);
typedef std::pair<C::const_iterator, C::const_iterator> Eq;
@@ -182,7 +184,9 @@ int main(int, char**)
test_compare<std::equal_to<int> >(3),
A(4)
);
+ C::iterator it0 = c0.begin();
c = std::move(c0);
+ assert(it0 == c.begin()); // Iterators remain valid
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 6);
typedef std::pair<C::const_iterator, C::const_iterator> Eq;
@@ -242,7 +246,9 @@ int main(int, char**)
test_compare<std::equal_to<int> >(3),
A()
);
+ C::iterator it0 = c0.begin();
c = std::move(c0);
+ assert(it0 == c.begin()); // Iterators remain valid
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 6);
typedef std::pair<C::const_iterator, C::const_iterator> Eq;
diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp
index a0a707c760028..d61d58a5ea61f 100644
--- a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp
@@ -82,7 +82,9 @@ int main(int, char**)
test_compare<std::equal_to<int> >(9),
test_allocator<std::pair<const int, std::string> >(10)
);
+ C::iterator it0 = c0.begin();
C c = std::move(c0);
+ assert(it0 == c.begin()); // Iterators remain valid
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 6);
typedef std::pair<C::const_iterator, C::const_iterator> Eq;
@@ -166,7 +168,9 @@ int main(int, char**)
test_compare<std::equal_to<int> >(9),
min_allocator<std::pair<const int, std::string> >()
);
+ C::iterator it0 = c0.begin();
C c = std::move(c0);
+ assert(it0 == c.begin()); // Iterators remain valid
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 6);
typedef std::pair<C::const_iterator, C::const_iterator> Eq;
diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_non_member.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_non_member.pass.cpp
index 9fcd6ccd3b31d..1d0532fcb644a 100644
--- a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_non_member.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_non_member.pass.cpp
@@ -77,6 +77,7 @@ int main(int, char**)
C c1(0, Hash(1), Compare(1), Alloc(1, 1));
C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
c2.max_load_factor(2);
+ C::iterator it2 = c2.begin();
swap(c1, c2);
assert(c1.bucket_count() >= 8);
@@ -95,6 +96,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
assert(c1.max_load_factor() == 2);
+ assert(it2 == c1.begin()); // Iterators are not invalidated
LIBCPP_ASSERT(c2.bucket_count() == 0);
assert(c2.size() == 0);
@@ -123,6 +125,7 @@ int main(int, char**)
C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
C c2(0, Hash(2), Compare(2), Alloc(1, 2));
c2.max_load_factor(2);
+ C::iterator it1 = c1.begin();
swap(c1, c2);
LIBCPP_ASSERT(c1.bucket_count() == 0);
@@ -151,6 +154,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
assert(c2.max_load_factor() == 1);
+ assert(it1 == c2.begin()); // Iterators are not invalidated
}
{
typedef test_hash<std::hash<int> > Hash;
@@ -181,6 +185,8 @@ int main(int, char**)
C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
c2.max_load_factor(2);
+ C::iterator it1 = c1.begin();
+ C::iterator it2 = c2.begin();
swap(c1, c2);
assert(c1.bucket_count() >= 8);
@@ -199,6 +205,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
assert(c1.max_load_factor() == 2);
+ assert(it2 == c1.begin()); // Iterators are not invalidated
assert(c2.bucket_count() >= 6);
assert(c2.size() == 6);
@@ -217,6 +224,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
assert(c2.max_load_factor() == 1);
+ assert(it1 == c2.begin()); // Iterators are not invalidated
}
{
diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp
index 9a9069e462d91..26c9c592927cf 100644
--- a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp
@@ -105,6 +105,7 @@ int main(int, char**)
test_compare<std::equal_to<int> >(3),
A(10)
);
+ C::iterator it0 = c0.begin();
c = std::move(c0);
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 6);
@@ -120,6 +121,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
assert(c.max_load_factor() == 1);
+ assert(it0 == c.begin()); // Iterators remain valid
}
{
typedef other_allocator<int> A;
@@ -150,6 +152,7 @@ int main(int, char**)
test_compare<std::equal_to<int> >(3),
A(4)
);
+ C::iterator it0 = c0.begin();
c = std::move(c0);
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 6);
@@ -165,6 +168,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
assert(c.max_load_factor() == 1);
+ assert(it0 == c.begin()); // Iterators remain valid
}
{
typedef test_allocator<int> A;
@@ -195,6 +199,7 @@ int main(int, char**)
test_compare<std::equal_to<int> >(3),
A()
);
+ C::iterator it0 = c0.begin();
c = std::move(c0);
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 6);
@@ -210,6 +215,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
assert(c.max_load_factor() == 1);
+ assert(it0 == c.begin()); // Iterators remain valid
}
{
typedef min_allocator<int> A;
@@ -240,6 +246,7 @@ int main(int, char**)
test_compare<std::equal_to<int> >(3),
A()
);
+ C::iterator it0 = c0.begin();
c = std::move(c0);
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 6);
@@ -255,6 +262,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
assert(c.max_load_factor() == 1);
+ assert(it0 == c.begin()); // Iterators remain valid
}
return 0;
diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move.pass.cpp
index fbb4f5fbe11a9..fa02494c19cc1 100644
--- a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move.pass.cpp
@@ -77,7 +77,9 @@ int main(int, char**)
test_compare<std::equal_to<int> >(9),
test_allocator<int>(10)
);
+ C::iterator it0 = c0.begin();
C c = std::move(c0);
+ assert(it0 == c.begin()); // Iterators remain valid
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 6);
assert(c.count(1) == 2);
@@ -142,7 +144,9 @@ int main(int, char**)
test_compare<std::equal_to<int> >(9),
min_allocator<int>()
);
+ C::iterator it0 = c0.begin();
C c = std::move(c0);
+ assert(it0 == c.begin()); // Iterators remain valid
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 6);
assert(c.count(1) == 2);
diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_non_member.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_non_member.pass.cpp
index 706c995f3de5a..5b5a4cd37392f 100644
--- a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_non_member.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_non_member.pass.cpp
@@ -74,6 +74,7 @@ int main(int, char**)
C c1(0, Hash(1), Compare(1), Alloc(1, 1));
C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
c2.max_load_factor(2);
+ C::iterator it2 = c2.begin();
swap(c1, c2);
assert(c1.bucket_count() >= 8);
@@ -92,6 +93,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
assert(c1.max_load_factor() == 2);
+ assert(it2 == c1.begin()); // Iterators are not invalidated
LIBCPP_ASSERT(c2.bucket_count() == 0);
assert(c2.size() == 0);
@@ -120,6 +122,7 @@ int main(int, char**)
C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
C c2(0, Hash(2), Compare(2), Alloc(1, 2));
c2.max_load_factor(2);
+ C::iterator it1 = c1.begin();
swap(c1, c2);
LIBCPP_ASSERT(c1.bucket_count() == 0);
@@ -143,6 +146,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
assert(c2.max_load_factor() == 1);
+ assert(it1 == c2.begin()); // Iterators are not invalidated
}
{
typedef test_hash<std::hash<int> > Hash;
@@ -173,6 +177,8 @@ int main(int, char**)
C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
c2.max_load_factor(2);
+ C::iterator it1 = c1.begin();
+ C::iterator it2 = c2.begin();
swap(c1, c2);
assert(c1.bucket_count() >= 8);
@@ -191,6 +197,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
assert(c1.max_load_factor() == 2);
+ assert(it2 == c1.begin()); // Iterators are not invalidated
assert(c2.bucket_count() >= 6);
assert(c2.size() == 6);
@@ -204,6 +211,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
assert(c2.max_load_factor() == 1);
+ assert(it1 == c2.begin()); // Iterators are not invalidated
}
{
diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_move.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_move.pass.cpp
index 276d7244ebe52..1edbe0b9174cf 100644
--- a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_move.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_move.pass.cpp
@@ -104,6 +104,7 @@ int main(int, char**)
test_compare<std::equal_to<int> >(3),
A(10)
);
+ C::iterator it0 = c0.begin();
c = std::move(c0);
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 4);
@@ -119,6 +120,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
assert(c.max_load_factor() == 1);
+ assert(it0 == c.begin()); // Iterators remain valid
}
{
typedef other_allocator<int> A;
@@ -149,6 +151,7 @@ int main(int, char**)
test_compare<std::equal_to<int> >(3),
A(4)
);
+ C::iterator it0 = c0.begin();
c = std::move(c0);
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 4);
@@ -164,6 +167,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
assert(c.max_load_factor() == 1);
+ assert(it0 == c.begin()); // Iterators remain valid
}
{
typedef min_allocator<int> A;
@@ -194,6 +198,7 @@ int main(int, char**)
test_compare<std::equal_to<int> >(3),
A()
);
+ C::iterator it0 = c0.begin();
c = std::move(c0);
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 4);
@@ -209,6 +214,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
assert(c.max_load_factor() == 1);
+ assert(it0 == c.begin()); // Iterators remain valid
}
return 0;
diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move.pass.cpp
index 2fc64edd3918f..dd3822e2ff3af 100644
--- a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move.pass.cpp
@@ -77,7 +77,9 @@ int main(int, char**)
test_compare<std::equal_to<int> >(9),
test_allocator<int>(10)
);
+ C::iterator it0 = c0.begin();
C c = std::move(c0);
+ assert(it0 == c.begin()); // Iterators remain valid
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 4);
assert(c.count(1) == 1);
@@ -142,7 +144,9 @@ int main(int, char**)
test_compare<std::equal_to<int> >(9),
min_allocator<int>()
);
+ C::iterator it0 = c0.begin();
C c = std::move(c0);
+ assert(it0 == c.begin()); // Iterators remain valid
LIBCPP_ASSERT(c.bucket_count() == 7);
assert(c.size() == 4);
assert(c.count(1) == 1);
diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.swap/swap_non_member.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.swap/swap_non_member.pass.cpp
index 8f1d9f0c3ee37..c128bd5fb6922 100644
--- a/libcxx/test/std/containers/unord/unord.set/unord.set.swap/swap_non_member.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.set/unord.set.swap/swap_non_member.pass.cpp
@@ -74,6 +74,7 @@ int main(int, char**)
C c1(0, Hash(1), Compare(1), Alloc(1, 1));
C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
c2.max_load_factor(2);
+ C::iterator it2 = c2.begin();
swap(c1, c2);
assert(c1.bucket_count() >= 8);
@@ -92,6 +93,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
assert(c1.max_load_factor() == 2);
+ assert(it2 == c1.begin()); // Iterators are not invalidated
LIBCPP_ASSERT(c2.bucket_count() == 0);
assert(c2.size() == 0);
@@ -120,6 +122,7 @@ int main(int, char**)
C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
C c2(0, Hash(2), Compare(2), Alloc(1, 2));
c2.max_load_factor(2);
+ C::iterator it1 = c1.begin();
swap(c1, c2);
LIBCPP_ASSERT(c1.bucket_count() == 0);
@@ -143,6 +146,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
assert(c2.max_load_factor() == 1);
+ assert(it1 == c2.begin()); // Iterators are not invalidated
}
{
typedef test_hash<std::hash<int> > Hash;
@@ -173,6 +177,8 @@ int main(int, char**)
C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
c2.max_load_factor(2);
+ C::iterator it1 = c1.begin();
+ C::iterator it2 = c2.begin();
swap(c1, c2);
assert(c1.bucket_count() >= 8);
@@ -191,6 +197,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
assert(c1.max_load_factor() == 2);
+ assert(it2 == c1.begin()); // Iterators are not invalidated
assert(c2.bucket_count() >= 4);
assert(c2.size() == 4);
@@ -204,6 +211,7 @@ int main(int, char**)
assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
assert(c2.max_load_factor() == 1);
+ assert(it1 == c2.begin()); // Iterators are not invalidated
}
{
More information about the libcxx-commits
mailing list