Fix Bug 38644: multimap::clear() missing exception specifier. Add noexcept tests for all the containers that have clear().
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@340385 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/map b/include/map
index 559ec48..4700a09 100644
--- a/include/map
+++ b/include/map
@@ -1884,7 +1884,7 @@
#endif
_LIBCPP_INLINE_VISIBILITY
- void clear() {__tree_.clear();}
+ void clear() _NOEXCEPT {__tree_.clear();}
_LIBCPP_INLINE_VISIBILITY
void swap(multimap& __m)
diff --git a/test/std/containers/associative/map/map.modifiers/clear.pass.cpp b/test/std/containers/associative/map/map.modifiers/clear.pass.cpp
index 1f36a6f..ab4642f 100644
--- a/test/std/containers/associative/map/map.modifiers/clear.pass.cpp
+++ b/test/std/containers/associative/map/map.modifiers/clear.pass.cpp
@@ -11,11 +11,12 @@
// class map
-// void clear();
+// void clear() noexcept;
#include <map>
#include <cassert>
+#include "test_macros.h"
#include "min_allocator.h"
int main()
@@ -36,6 +37,7 @@
};
M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 8);
+ ASSERT_NOEXCEPT(m.clear());
m.clear();
assert(m.size() == 0);
}
@@ -56,6 +58,7 @@
};
M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 8);
+ ASSERT_NOEXCEPT(m.clear());
m.clear();
assert(m.size() == 0);
}
diff --git a/test/std/containers/associative/multimap/multimap.modifiers/clear.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/clear.pass.cpp
index 321f4d0..546a406 100644
--- a/test/std/containers/associative/multimap/multimap.modifiers/clear.pass.cpp
+++ b/test/std/containers/associative/multimap/multimap.modifiers/clear.pass.cpp
@@ -11,11 +11,12 @@
// class multimap
-// void clear();
+// void clear() noexcept;
#include <map>
#include <cassert>
+#include "test_macros.h"
#include "min_allocator.h"
int main()
@@ -36,6 +37,7 @@
};
M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 8);
+ ASSERT_NOEXCEPT(m.clear());
m.clear();
assert(m.size() == 0);
}
@@ -56,6 +58,7 @@
};
M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 8);
+ ASSERT_NOEXCEPT(m.clear());
m.clear();
assert(m.size() == 0);
}
diff --git a/test/std/containers/associative/multiset/clear.pass.cpp b/test/std/containers/associative/multiset/clear.pass.cpp
index f762ef7..59ee02e 100644
--- a/test/std/containers/associative/multiset/clear.pass.cpp
+++ b/test/std/containers/associative/multiset/clear.pass.cpp
@@ -11,11 +11,12 @@
// class multiset
-// void clear();
+// void clear() noexcept;
#include <set>
#include <cassert>
+#include "test_macros.h"
#include "min_allocator.h"
int main()
@@ -36,6 +37,7 @@
};
M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 8);
+ ASSERT_NOEXCEPT(m.clear());
m.clear();
assert(m.size() == 0);
}
@@ -56,6 +58,7 @@
};
M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 8);
+ ASSERT_NOEXCEPT(m.clear());
m.clear();
assert(m.size() == 0);
}
diff --git a/test/std/containers/associative/set/clear.pass.cpp b/test/std/containers/associative/set/clear.pass.cpp
index 7a5bf4b..1be3ed2 100644
--- a/test/std/containers/associative/set/clear.pass.cpp
+++ b/test/std/containers/associative/set/clear.pass.cpp
@@ -11,11 +11,12 @@
// class set
-// void clear();
+// void clear() noexcept;
#include <set>
#include <cassert>
+#include "test_macros.h"
#include "min_allocator.h"
int main()
@@ -36,6 +37,7 @@
};
M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 8);
+ ASSERT_NOEXCEPT(m.clear());
m.clear();
assert(m.size() == 0);
}
@@ -56,6 +58,7 @@
};
M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
assert(m.size() == 8);
+ ASSERT_NOEXCEPT(m.clear());
m.clear();
assert(m.size() == 0);
}
diff --git a/test/std/containers/sequences/deque/deque.modifiers/clear.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/clear.pass.cpp
new file mode 100644
index 0000000..943b6e8
--- /dev/null
+++ b/test/std/containers/sequences/deque/deque.modifiers/clear.pass.cpp
@@ -0,0 +1,67 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <deque>
+
+// void clear() noexcept;
+
+#include <deque>
+#include <cassert>
+
+#include "test_macros.h"
+#include "../../../NotConstructible.h"
+#include "min_allocator.h"
+
+int main()
+{
+ {
+ typedef NotConstructible T;
+ typedef std::deque<T> C;
+ C c;
+ ASSERT_NOEXCEPT(c.clear());
+ c.clear();
+ assert(distance(c.begin(), c.end()) == 0);
+ }
+ {
+ typedef int T;
+ typedef std::deque<T> C;
+ const T t[] = {0, 1, 2, 3, 4};
+ C c(std::begin(t), std::end(t));
+
+ ASSERT_NOEXCEPT(c.clear());
+ c.clear();
+ assert(distance(c.begin(), c.end()) == 0);
+
+ c.clear();
+ assert(distance(c.begin(), c.end()) == 0);
+ }
+#if TEST_STD_VER >= 11
+ {
+ typedef NotConstructible T;
+ typedef std::deque<T, min_allocator<T>> C;
+ C c;
+ ASSERT_NOEXCEPT(c.clear());
+ c.clear();
+ assert(distance(c.begin(), c.end()) == 0);
+ }
+ {
+ typedef int T;
+ typedef std::deque<T, min_allocator<T>> C;
+ const T t[] = {0, 1, 2, 3, 4};
+ C c(std::begin(t), std::end(t));
+
+ ASSERT_NOEXCEPT(c.clear());
+ c.clear();
+ assert(distance(c.begin(), c.end()) == 0);
+
+ c.clear();
+ assert(distance(c.begin(), c.end()) == 0);
+ }
+#endif
+}
diff --git a/test/std/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp b/test/std/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp
index 0e625ac..6cdf8d5 100644
--- a/test/std/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp
+++ b/test/std/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp
@@ -9,11 +9,12 @@
// <forward_list>
-// void clear();
+// void clear() noexcept;
#include <forward_list>
#include <cassert>
+#include "test_macros.h"
#include "../../../NotConstructible.h"
#include "min_allocator.h"
@@ -23,6 +24,7 @@
typedef NotConstructible T;
typedef std::forward_list<T> C;
C c;
+ ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(distance(c.begin(), c.end()) == 0);
}
@@ -32,6 +34,7 @@
const T t[] = {0, 1, 2, 3, 4};
C c(std::begin(t), std::end(t));
+ ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(distance(c.begin(), c.end()) == 0);
@@ -43,6 +46,7 @@
typedef NotConstructible T;
typedef std::forward_list<T, min_allocator<T>> C;
C c;
+ ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(distance(c.begin(), c.end()) == 0);
}
@@ -52,6 +56,7 @@
const T t[] = {0, 1, 2, 3, 4};
C c(std::begin(t), std::end(t));
+ ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(distance(c.begin(), c.end()) == 0);
diff --git a/test/std/containers/sequences/list/list.modifiers/clear.pass.cpp b/test/std/containers/sequences/list/list.modifiers/clear.pass.cpp
index 5d8c41f..1d7cb80 100644
--- a/test/std/containers/sequences/list/list.modifiers/clear.pass.cpp
+++ b/test/std/containers/sequences/list/list.modifiers/clear.pass.cpp
@@ -9,11 +9,12 @@
// <list>
-// void clear();
+// void clear() noexcept;
#include <list>
#include <cassert>
+#include "test_macros.h"
#include "min_allocator.h"
int main()
@@ -21,6 +22,7 @@
{
int a[] = {1, 2, 3};
std::list<int> c(a, a+3);
+ ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.empty());
}
@@ -28,6 +30,7 @@
{
int a[] = {1, 2, 3};
std::list<int, min_allocator<int>> c(a, a+3);
+ ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.empty());
}
diff --git a/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp
index 5f053eb..5357ba4 100644
--- a/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp
+++ b/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp
@@ -9,11 +9,12 @@
// <vector>
-// void clear();
+// void clear() noexcept;
#include <vector>
#include <cassert>
+#include "test_macros.h"
#include "min_allocator.h"
#include "asan_testing.h"
@@ -22,6 +23,7 @@
{
int a[] = {1, 2, 3};
std::vector<int> c(a, a+3);
+ ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.empty());
LIBCPP_ASSERT(c.__invariants());
@@ -31,6 +33,7 @@
{
int a[] = {1, 2, 3};
std::vector<int, min_allocator<int>> c(a, a+3);
+ ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.empty());
LIBCPP_ASSERT(c.__invariants());
diff --git a/test/std/containers/unord/unord.map/unord.map.modifiers/clear.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/clear.pass.cpp
index 106423e..9212a5e 100644
--- a/test/std/containers/unord/unord.map/unord.map.modifiers/clear.pass.cpp
+++ b/test/std/containers/unord/unord.map/unord.map.modifiers/clear.pass.cpp
@@ -13,12 +13,13 @@
// class Alloc = allocator<pair<const Key, T>>>
// class unordered_map
-// void clear()
+// void clear() noexcept;
#include <unordered_map>
#include <string>
#include <cassert>
+#include "test_macros.h"
#include "min_allocator.h"
int main()
@@ -36,6 +37,7 @@
P(2, "four"),
};
C c(a, a + sizeof(a)/sizeof(a[0]));
+ ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.size() == 0);
}
@@ -54,6 +56,7 @@
P(2, "four"),
};
C c(a, a + sizeof(a)/sizeof(a[0]));
+ ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.size() == 0);
}
diff --git a/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/clear.pass.cpp b/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/clear.pass.cpp
index 891d449..15c7820 100644
--- a/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/clear.pass.cpp
+++ b/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/clear.pass.cpp
@@ -13,12 +13,13 @@
// class Alloc = allocator<pair<const Key, T>>>
// class unordered_multimap
-// void clear()
+// void clear() noexcept;
#include <unordered_map>
#include <string>
#include <cassert>
+#include "test_macros.h"
#include "min_allocator.h"
int main()
@@ -36,6 +37,7 @@
P(2, "four"),
};
C c(a, a + sizeof(a)/sizeof(a[0]));
+ ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.size() == 0);
}
@@ -54,6 +56,7 @@
P(2, "four"),
};
C c(a, a + sizeof(a)/sizeof(a[0]));
+ ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.size() == 0);
}
diff --git a/test/std/containers/unord/unord.multiset/clear.pass.cpp b/test/std/containers/unord/unord.multiset/clear.pass.cpp
index 57dbb8b..b699d06 100644
--- a/test/std/containers/unord/unord.multiset/clear.pass.cpp
+++ b/test/std/containers/unord/unord.multiset/clear.pass.cpp
@@ -13,11 +13,12 @@
// class Alloc = allocator<Value>>
// class unordered_multiset
-// void clear()
+// void clear() noexcept;
#include <unordered_set>
#include <cassert>
+#include "test_macros.h"
#include "min_allocator.h"
int main()
@@ -35,6 +36,7 @@
P(2)
};
C c(a, a + sizeof(a)/sizeof(a[0]));
+ ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.size() == 0);
}
@@ -53,6 +55,7 @@
P(2)
};
C c(a, a + sizeof(a)/sizeof(a[0]));
+ ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.size() == 0);
}
diff --git a/test/std/containers/unord/unord.set/clear.pass.cpp b/test/std/containers/unord/unord.set/clear.pass.cpp
index 8ebf748..2f22391 100644
--- a/test/std/containers/unord/unord.set/clear.pass.cpp
+++ b/test/std/containers/unord/unord.set/clear.pass.cpp
@@ -13,11 +13,12 @@
// class Alloc = allocator<Value>>
// class unordered_set
-// void clear()
+// void clear() noexcept;
#include <unordered_set>
#include <cassert>
+#include "test_macros.h"
#include "min_allocator.h"
int main()
@@ -35,6 +36,7 @@
P(2)
};
C c(a, a + sizeof(a)/sizeof(a[0]));
+ ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.size() == 0);
}
@@ -52,6 +54,7 @@
P(2)
};
C c(a, a + sizeof(a)/sizeof(a[0]));
+ ASSERT_NOEXCEPT(c.clear());
c.clear();
assert(c.size() == 0);
}