From 934e9a3976db9d3535c9443e8dbbf96eca06c9a7 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 22 Aug 2018 04:28:43 +0000 Subject: [PATCH] Fix Bug 38644: multimap::clear() missing exception specifier. Add noexcept tests for all the containers that have clear(). llvm-svn: 340385 --- libcxx/include/map | 2 +- .../map/map.modifiers/clear.pass.cpp | 5 +- .../multimap.modifiers/clear.pass.cpp | 5 +- .../associative/multiset/clear.pass.cpp | 5 +- .../containers/associative/set/clear.pass.cpp | 5 +- .../deque/deque.modifiers/clear.pass.cpp | 67 +++++++++++++++++++ .../forwardlist.modifiers/clear.pass.cpp | 7 +- .../list/list.modifiers/clear.pass.cpp | 5 +- .../vector/vector.modifiers/clear.pass.cpp | 5 +- .../unord.map.modifiers/clear.pass.cpp | 5 +- .../unord.multimap.modifiers/clear.pass.cpp | 5 +- .../unord/unord.multiset/clear.pass.cpp | 5 +- .../containers/unord/unord.set/clear.pass.cpp | 5 +- 13 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/clear.pass.cpp diff --git a/libcxx/include/map b/libcxx/include/map index 559ec484aca0..4700a09eda29 100644 --- a/libcxx/include/map +++ b/libcxx/include/map @@ -1884,7 +1884,7 @@ public: #endif _LIBCPP_INLINE_VISIBILITY - void clear() {__tree_.clear();} + void clear() _NOEXCEPT {__tree_.clear();} _LIBCPP_INLINE_VISIBILITY void swap(multimap& __m) diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/clear.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/clear.pass.cpp index 1f36a6f10cb0..ab4642fa88e6 100644 --- a/libcxx/test/std/containers/associative/map/map.modifiers/clear.pass.cpp +++ b/libcxx/test/std/containers/associative/map/map.modifiers/clear.pass.cpp @@ -11,11 +11,12 @@ // class map -// void clear(); +// void clear() noexcept; #include #include +#include "test_macros.h" #include "min_allocator.h" int main() @@ -36,6 +37,7 @@ int main() }; 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 @@ int main() }; 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/libcxx/test/std/containers/associative/multimap/multimap.modifiers/clear.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/clear.pass.cpp index 321f4d0bd000..546a406fe1bf 100644 --- a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/clear.pass.cpp +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/clear.pass.cpp @@ -11,11 +11,12 @@ // class multimap -// void clear(); +// void clear() noexcept; #include #include +#include "test_macros.h" #include "min_allocator.h" int main() @@ -36,6 +37,7 @@ int main() }; 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 @@ int main() }; 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/libcxx/test/std/containers/associative/multiset/clear.pass.cpp b/libcxx/test/std/containers/associative/multiset/clear.pass.cpp index f762ef7d3504..59ee02ece1d2 100644 --- a/libcxx/test/std/containers/associative/multiset/clear.pass.cpp +++ b/libcxx/test/std/containers/associative/multiset/clear.pass.cpp @@ -11,11 +11,12 @@ // class multiset -// void clear(); +// void clear() noexcept; #include #include +#include "test_macros.h" #include "min_allocator.h" int main() @@ -36,6 +37,7 @@ int main() }; 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 @@ int main() }; 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/libcxx/test/std/containers/associative/set/clear.pass.cpp b/libcxx/test/std/containers/associative/set/clear.pass.cpp index 7a5bf4b14a71..1be3ed2b8877 100644 --- a/libcxx/test/std/containers/associative/set/clear.pass.cpp +++ b/libcxx/test/std/containers/associative/set/clear.pass.cpp @@ -11,11 +11,12 @@ // class set -// void clear(); +// void clear() noexcept; #include #include +#include "test_macros.h" #include "min_allocator.h" int main() @@ -36,6 +37,7 @@ int main() }; 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 @@ int main() }; 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/libcxx/test/std/containers/sequences/deque/deque.modifiers/clear.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/clear.pass.cpp new file mode 100644 index 000000000000..943b6e8e11ca --- /dev/null +++ b/libcxx/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. +// +//===----------------------------------------------------------------------===// + +// + +// void clear() noexcept; + +#include +#include + +#include "test_macros.h" +#include "../../../NotConstructible.h" +#include "min_allocator.h" + +int main() +{ + { + typedef NotConstructible T; + typedef std::deque C; + C c; + ASSERT_NOEXCEPT(c.clear()); + c.clear(); + assert(distance(c.begin(), c.end()) == 0); + } + { + typedef int T; + typedef std::deque 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> C; + C c; + ASSERT_NOEXCEPT(c.clear()); + c.clear(); + assert(distance(c.begin(), c.end()) == 0); + } + { + typedef int T; + typedef std::deque> 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/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp index 0e625ac76a02..6cdf8d57ace3 100644 --- a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp @@ -9,11 +9,12 @@ // -// void clear(); +// void clear() noexcept; #include #include +#include "test_macros.h" #include "../../../NotConstructible.h" #include "min_allocator.h" @@ -23,6 +24,7 @@ int main() typedef NotConstructible T; typedef std::forward_list C; C c; + ASSERT_NOEXCEPT(c.clear()); c.clear(); assert(distance(c.begin(), c.end()) == 0); } @@ -32,6 +34,7 @@ int main() 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 @@ int main() typedef NotConstructible T; typedef std::forward_list> C; C c; + ASSERT_NOEXCEPT(c.clear()); c.clear(); assert(distance(c.begin(), c.end()) == 0); } @@ -52,6 +56,7 @@ int main() 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/libcxx/test/std/containers/sequences/list/list.modifiers/clear.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/clear.pass.cpp index 5d8c41fa1976..1d7cb80eb65b 100644 --- a/libcxx/test/std/containers/sequences/list/list.modifiers/clear.pass.cpp +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/clear.pass.cpp @@ -9,11 +9,12 @@ // -// void clear(); +// void clear() noexcept; #include #include +#include "test_macros.h" #include "min_allocator.h" int main() @@ -21,6 +22,7 @@ int main() { int a[] = {1, 2, 3}; std::list c(a, a+3); + ASSERT_NOEXCEPT(c.clear()); c.clear(); assert(c.empty()); } @@ -28,6 +30,7 @@ int main() { int a[] = {1, 2, 3}; std::list> c(a, a+3); + ASSERT_NOEXCEPT(c.clear()); c.clear(); assert(c.empty()); } diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp index 5f053eb8565a..5357ba4cb284 100644 --- a/libcxx/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/clear.pass.cpp @@ -9,11 +9,12 @@ // -// void clear(); +// void clear() noexcept; #include #include +#include "test_macros.h" #include "min_allocator.h" #include "asan_testing.h" @@ -22,6 +23,7 @@ int main() { int a[] = {1, 2, 3}; std::vector c(a, a+3); + ASSERT_NOEXCEPT(c.clear()); c.clear(); assert(c.empty()); LIBCPP_ASSERT(c.__invariants()); @@ -31,6 +33,7 @@ int main() { int a[] = {1, 2, 3}; std::vector> c(a, a+3); + ASSERT_NOEXCEPT(c.clear()); c.clear(); assert(c.empty()); LIBCPP_ASSERT(c.__invariants()); diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/clear.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/clear.pass.cpp index 106423ebfbe9..9212a5e3def3 100644 --- a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/clear.pass.cpp +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/clear.pass.cpp @@ -13,12 +13,13 @@ // class Alloc = allocator>> // class unordered_map -// void clear() +// void clear() noexcept; #include #include #include +#include "test_macros.h" #include "min_allocator.h" int main() @@ -36,6 +37,7 @@ int main() 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 @@ int main() 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/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/clear.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/clear.pass.cpp index 891d44911eb0..15c78208a616 100644 --- a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/clear.pass.cpp +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/clear.pass.cpp @@ -13,12 +13,13 @@ // class Alloc = allocator>> // class unordered_multimap -// void clear() +// void clear() noexcept; #include #include #include +#include "test_macros.h" #include "min_allocator.h" int main() @@ -36,6 +37,7 @@ int main() 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 @@ int main() 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/libcxx/test/std/containers/unord/unord.multiset/clear.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/clear.pass.cpp index 57dbb8b1faaa..b699d0624ddd 100644 --- a/libcxx/test/std/containers/unord/unord.multiset/clear.pass.cpp +++ b/libcxx/test/std/containers/unord/unord.multiset/clear.pass.cpp @@ -13,11 +13,12 @@ // class Alloc = allocator> // class unordered_multiset -// void clear() +// void clear() noexcept; #include #include +#include "test_macros.h" #include "min_allocator.h" int main() @@ -35,6 +36,7 @@ int main() 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 @@ int main() P(2) }; C c(a, a + sizeof(a)/sizeof(a[0])); + ASSERT_NOEXCEPT(c.clear()); c.clear(); assert(c.size() == 0); } diff --git a/libcxx/test/std/containers/unord/unord.set/clear.pass.cpp b/libcxx/test/std/containers/unord/unord.set/clear.pass.cpp index 8ebf748eb8da..2f22391297c4 100644 --- a/libcxx/test/std/containers/unord/unord.set/clear.pass.cpp +++ b/libcxx/test/std/containers/unord/unord.set/clear.pass.cpp @@ -13,11 +13,12 @@ // class Alloc = allocator> // class unordered_set -// void clear() +// void clear() noexcept; #include #include +#include "test_macros.h" #include "min_allocator.h" int main() @@ -35,6 +36,7 @@ int main() 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 @@ int main() P(2) }; C c(a, a + sizeof(a)/sizeof(a[0])); + ASSERT_NOEXCEPT(c.clear()); c.clear(); assert(c.size() == 0); }