diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:54:09 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:54:09 +0000 |
| commit | b4c64ad90b81d2a779786b7edb4c5c6dd28cc57d (patch) | |
| tree | 13f237c02db4d1894ab06884d1b739344766bede /test/std/containers | |
| parent | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (diff) | |
Notes
Diffstat (limited to 'test/std/containers')
110 files changed, 758 insertions, 506 deletions
diff --git a/test/std/containers/associative/map/allocator_mismatch.fail.cpp b/test/std/containers/associative/map/allocator_mismatch.fail.cpp new file mode 100644 index 000000000000..f5da14539c47 --- /dev/null +++ b/test/std/containers/associative/map/allocator_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <map> +// The container's value type must be the same as the allocator's value type + +#include <map> + +int main() +{ + std::map<int, int, std::less<int>, std::allocator<long> > m; +} diff --git a/test/std/containers/associative/map/compare.pass.cpp b/test/std/containers/associative/map/compare.pass.cpp index aa4d5999ff46..26ac7af7d908 100644 --- a/test/std/containers/associative/map/compare.pass.cpp +++ b/test/std/containers/associative/map/compare.pass.cpp @@ -17,16 +17,36 @@ // http://llvm.org/bugs/show_bug.cgi?id=16549 #include <map> +#include <utility> +#include <cassert> struct Key { template <typename T> Key(const T&) {} bool operator< (const Key&) const { return false; } }; -int -main() +int main() { - std::map<Key, int>::iterator it = std::map<Key, int>().find(Key(0)); - std::pair<std::map<Key, int>::iterator, bool> result = - std::map<Key, int>().insert(std::make_pair(Key(0), 0)); + typedef std::map<Key, int> MapT; + typedef MapT::iterator Iter; + typedef std::pair<Iter, bool> IterBool; + { + MapT m_empty; + MapT m_contains; + m_contains[Key(0)] = 42; + + Iter it = m_empty.find(Key(0)); + assert(it == m_empty.end()); + it = m_contains.find(Key(0)); + assert(it != m_contains.end()); + } + { + MapT map; + IterBool result = map.insert(std::make_pair(Key(0), 42)); + assert(result.second); + assert(result.first->second = 42); + IterBool result2 = map.insert(std::make_pair(Key(0), 43)); + assert(!result2.second); + assert(map[Key(0)] == 42); + } } diff --git a/test/std/containers/associative/map/map.access/at.pass.cpp b/test/std/containers/associative/map/map.access/at.pass.cpp index 86b1e3d2dfa6..0da28507fce3 100644 --- a/test/std/containers/associative/map/map.access/at.pass.cpp +++ b/test/std/containers/associative/map/map.access/at.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <map> // class map diff --git a/test/std/containers/associative/map/map.access/index_rv_key.pass.cpp b/test/std/containers/associative/map/map.access/index_rv_key.pass.cpp index d14603e1a281..6511dcc85f53 100644 --- a/test/std/containers/associative/map/map.access/index_rv_key.pass.cpp +++ b/test/std/containers/associative/map/map.access/index_rv_key.pass.cpp @@ -16,14 +16,14 @@ #include <map> #include <cassert> +#include "test_macros.h" #include "MoveOnly.h" #include "min_allocator.h" int main() { -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if TEST_STD_VER >= 11 { - typedef std::pair<MoveOnly, double> V; std::map<MoveOnly, double> m; assert(m.size() == 0); assert(m[1] == 0.0); @@ -37,10 +37,8 @@ int main() assert(m[6] == 6.5); assert(m.size() == 2); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES -#if __cplusplus >= 201103L { - typedef std::pair<MoveOnly, double> V; + typedef std::pair<const MoveOnly, double> V; std::map<MoveOnly, double, std::less<MoveOnly>, min_allocator<V>> m; assert(m.size() == 0); assert(m[1] == 0.0); diff --git a/test/std/containers/associative/map/map.cons/default_noexcept.pass.cpp b/test/std/containers/associative/map/map.cons/default_noexcept.pass.cpp index 1f11fc9582ed..dedc89bd435e 100644 --- a/test/std/containers/associative/map/map.cons/default_noexcept.pass.cpp +++ b/test/std/containers/associative/map/map.cons/default_noexcept.pass.cpp @@ -33,16 +33,17 @@ struct some_comp int main() { #if __has_feature(cxx_noexcept) + typedef std::pair<const MoveOnly, MoveOnly> V; { typedef std::map<MoveOnly, MoveOnly> C; static_assert(std::is_nothrow_default_constructible<C>::value, ""); } { - typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<V>> C; static_assert(std::is_nothrow_default_constructible<C>::value, ""); } { - typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<V>> C; static_assert(!std::is_nothrow_default_constructible<C>::value, ""); } { diff --git a/test/std/containers/associative/map/map.cons/dtor_noexcept.pass.cpp b/test/std/containers/associative/map/map.cons/dtor_noexcept.pass.cpp index eed26d3a6136..9baa19b53d05 100644 --- a/test/std/containers/associative/map/map.cons/dtor_noexcept.pass.cpp +++ b/test/std/containers/associative/map/map.cons/dtor_noexcept.pass.cpp @@ -31,16 +31,17 @@ struct some_comp int main() { #if __has_feature(cxx_noexcept) + typedef std::pair<const MoveOnly, MoveOnly> V; { typedef std::map<MoveOnly, MoveOnly> C; static_assert(std::is_nothrow_destructible<C>::value, ""); } { - typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<V>> C; static_assert(std::is_nothrow_destructible<C>::value, ""); } { - typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<V>> C; static_assert(std::is_nothrow_destructible<C>::value, ""); } { diff --git a/test/std/containers/associative/map/map.cons/move_assign_noexcept.pass.cpp b/test/std/containers/associative/map/map.cons/move_assign_noexcept.pass.cpp index f80b1d323178..3b28118b5b1e 100644 --- a/test/std/containers/associative/map/map.cons/move_assign_noexcept.pass.cpp +++ b/test/std/containers/associative/map/map.cons/move_assign_noexcept.pass.cpp @@ -33,16 +33,17 @@ struct some_comp int main() { #if __has_feature(cxx_noexcept) + typedef std::pair<const MoveOnly, MoveOnly> V; { typedef std::map<MoveOnly, MoveOnly> C; static_assert(std::is_nothrow_move_assignable<C>::value, ""); } { - typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<V>> C; static_assert(!std::is_nothrow_move_assignable<C>::value, ""); } { - typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<V>> C; static_assert(std::is_nothrow_move_assignable<C>::value, ""); } { diff --git a/test/std/containers/associative/map/map.cons/move_noexcept.pass.cpp b/test/std/containers/associative/map/map.cons/move_noexcept.pass.cpp index 9347b8329ae3..0f1fd396639e 100644 --- a/test/std/containers/associative/map/map.cons/move_noexcept.pass.cpp +++ b/test/std/containers/associative/map/map.cons/move_noexcept.pass.cpp @@ -31,16 +31,17 @@ struct some_comp int main() { #if __has_feature(cxx_noexcept) + typedef std::pair<const MoveOnly, MoveOnly> V; { typedef std::map<MoveOnly, MoveOnly> C; static_assert(std::is_nothrow_move_constructible<C>::value, ""); } { - typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<V>> C; static_assert(std::is_nothrow_move_constructible<C>::value, ""); } { - typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<V>> C; static_assert(std::is_nothrow_move_constructible<C>::value, ""); } { diff --git a/test/std/containers/associative/map/map.special/swap_noexcept.pass.cpp b/test/std/containers/associative/map/map.special/swap_noexcept.pass.cpp index 4598e9945d4e..f25dff2c86da 100644 --- a/test/std/containers/associative/map/map.special/swap_noexcept.pass.cpp +++ b/test/std/containers/associative/map/map.special/swap_noexcept.pass.cpp @@ -94,18 +94,19 @@ struct some_alloc3 int main() { #if __has_feature(cxx_noexcept) + typedef std::pair<const MoveOnly, MoveOnly> V; { typedef std::map<MoveOnly, MoveOnly> C; C c1, c2; static_assert(noexcept(swap(c1, c2)), ""); } { - typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<V>> C; C c1, c2; static_assert(noexcept(swap(c1, c2)), ""); } { - typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<V>> C; C c1, c2; static_assert(noexcept(swap(c1, c2)), ""); } @@ -117,28 +118,28 @@ int main() #if TEST_STD_VER >= 14 { // POCS allocator, throwable swap for comp - typedef std::map<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc <MoveOnly>> C; + typedef std::map<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc <V>> C; C c1, c2; static_assert(!noexcept(swap(c1, c2)), ""); } { // always equal allocator, throwable swap for comp - typedef std::map<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc2<MoveOnly>> C; + typedef std::map<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc2<V>> C; C c1, c2; static_assert(!noexcept(swap(c1, c2)), ""); } { // POCS allocator, nothrow swap for comp - typedef std::map<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc <MoveOnly>> C; + typedef std::map<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc <V>> C; C c1, c2; static_assert( noexcept(swap(c1, c2)), ""); } { // always equal allocator, nothrow swap for comp - typedef std::map<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc2<MoveOnly>> C; + typedef std::map<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc2<V>> C; C c1, c2; static_assert( noexcept(swap(c1, c2)), ""); } { // NOT always equal allocator, nothrow swap for comp - typedef std::map<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc3<MoveOnly>> C; + typedef std::map<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc3<V>> C; C c1, c2; static_assert( noexcept(swap(c1, c2)), ""); } diff --git a/test/std/containers/associative/multimap/allocator_mismatch.fail.cpp b/test/std/containers/associative/multimap/allocator_mismatch.fail.cpp new file mode 100644 index 000000000000..18823212f409 --- /dev/null +++ b/test/std/containers/associative/multimap/allocator_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <map> +// The container's value type must be the same as the allocator's value type + +#include <map> + +int main() +{ + std::multimap<int, int, std::less<int>, std::allocator<long> > m; +} diff --git a/test/std/containers/associative/multimap/multimap.cons/default_noexcept.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/default_noexcept.pass.cpp index d1db40b1fc7a..5f05a0dca28e 100644 --- a/test/std/containers/associative/multimap/multimap.cons/default_noexcept.pass.cpp +++ b/test/std/containers/associative/multimap/multimap.cons/default_noexcept.pass.cpp @@ -33,16 +33,17 @@ struct some_comp int main() { #if __has_feature(cxx_noexcept) + typedef std::pair<const MoveOnly, MoveOnly> V; { typedef std::multimap<MoveOnly, MoveOnly> C; static_assert(std::is_nothrow_default_constructible<C>::value, ""); } { - typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<V>> C; static_assert(std::is_nothrow_default_constructible<C>::value, ""); } { - typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<V>> C; static_assert(!std::is_nothrow_default_constructible<C>::value, ""); } { diff --git a/test/std/containers/associative/multimap/multimap.cons/dtor_noexcept.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/dtor_noexcept.pass.cpp index cb55e3fb33ec..dd1701240c63 100644 --- a/test/std/containers/associative/multimap/multimap.cons/dtor_noexcept.pass.cpp +++ b/test/std/containers/associative/multimap/multimap.cons/dtor_noexcept.pass.cpp @@ -31,16 +31,17 @@ struct some_comp int main() { #if __has_feature(cxx_noexcept) + typedef std::pair<const MoveOnly, MoveOnly> V; { typedef std::multimap<MoveOnly, MoveOnly> C; static_assert(std::is_nothrow_destructible<C>::value, ""); } { - typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<V>> C; static_assert(std::is_nothrow_destructible<C>::value, ""); } { - typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<V>> C; static_assert(std::is_nothrow_destructible<C>::value, ""); } { diff --git a/test/std/containers/associative/multimap/multimap.cons/move_assign_noexcept.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/move_assign_noexcept.pass.cpp index 8ad9e8b82fd1..635a8dca0357 100644 --- a/test/std/containers/associative/multimap/multimap.cons/move_assign_noexcept.pass.cpp +++ b/test/std/containers/associative/multimap/multimap.cons/move_assign_noexcept.pass.cpp @@ -33,16 +33,17 @@ struct some_comp int main() { #if __has_feature(cxx_noexcept) + typedef std::pair<const MoveOnly, MoveOnly> V; { typedef std::multimap<MoveOnly, MoveOnly> C; static_assert(std::is_nothrow_move_assignable<C>::value, ""); } { - typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<V>> C; static_assert(!std::is_nothrow_move_assignable<C>::value, ""); } { - typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<V>> C; static_assert(std::is_nothrow_move_assignable<C>::value, ""); } { diff --git a/test/std/containers/associative/multimap/multimap.cons/move_noexcept.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/move_noexcept.pass.cpp index 66ea8737fb75..0f31f04ff829 100644 --- a/test/std/containers/associative/multimap/multimap.cons/move_noexcept.pass.cpp +++ b/test/std/containers/associative/multimap/multimap.cons/move_noexcept.pass.cpp @@ -31,16 +31,17 @@ struct some_comp int main() { #if __has_feature(cxx_noexcept) + typedef std::pair<const MoveOnly, MoveOnly> V; { typedef std::multimap<MoveOnly, MoveOnly> C; static_assert(std::is_nothrow_move_constructible<C>::value, ""); } { - typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<V>> C; static_assert(std::is_nothrow_move_constructible<C>::value, ""); } { - typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<V>> C; static_assert(std::is_nothrow_move_constructible<C>::value, ""); } { diff --git a/test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp b/test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp index 1013c62804b8..e70ee1fae565 100644 --- a/test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp +++ b/test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp @@ -94,18 +94,19 @@ struct some_alloc3 int main() { #if __has_feature(cxx_noexcept) + typedef std::pair<const MoveOnly, MoveOnly> V; { typedef std::multimap<MoveOnly, MoveOnly> C; C c1, c2; static_assert(noexcept(swap(c1, c2)), ""); } { - typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<V>> C; C c1, c2; static_assert(noexcept(swap(c1, c2)), ""); } { - typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<V>> C; C c1, c2; static_assert(noexcept(swap(c1, c2)), ""); } @@ -117,28 +118,28 @@ int main() #if TEST_STD_VER >= 14 { // POCS allocator, throwable swap for comp - typedef std::multimap<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc <MoveOnly>> C; + typedef std::multimap<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc <V>> C; C c1, c2; static_assert(!noexcept(swap(c1, c2)), ""); } { // always equal allocator, throwable swap for comp - typedef std::multimap<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc2<MoveOnly>> C; + typedef std::multimap<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc2<V>> C; C c1, c2; static_assert(!noexcept(swap(c1, c2)), ""); } { // POCS allocator, nothrow swap for comp - typedef std::multimap<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc <MoveOnly>> C; + typedef std::multimap<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc <V>> C; C c1, c2; static_assert( noexcept(swap(c1, c2)), ""); } { // always equal allocator, nothrow swap for comp - typedef std::multimap<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc2<MoveOnly>> C; + typedef std::multimap<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc2<V>> C; C c1, c2; static_assert( noexcept(swap(c1, c2)), ""); } { // NOT always equal allocator, nothrow swap for comp - typedef std::map<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc3<MoveOnly>> C; + typedef std::map<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc3<V>> C; C c1, c2; static_assert( noexcept(swap(c1, c2)), ""); } diff --git a/test/std/containers/associative/multimap/scary.pass.cpp b/test/std/containers/associative/multimap/scary.pass.cpp index b99d9bc2df91..e6dc5aaca953 100644 --- a/test/std/containers/associative/multimap/scary.pass.cpp +++ b/test/std/containers/associative/multimap/scary.pass.cpp @@ -21,4 +21,5 @@ int main() typedef std::multimap<int, int> M2; M2::iterator i; M1::iterator j = i; + ((void)j); } diff --git a/test/std/containers/associative/multiset/allocator_mismatch.fail.cpp b/test/std/containers/associative/multiset/allocator_mismatch.fail.cpp new file mode 100644 index 000000000000..b2b30d6fdc1d --- /dev/null +++ b/test/std/containers/associative/multiset/allocator_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <set> +// The container's value type must be the same as the allocator's value type + +#include <set> + +int main() +{ + std::multiset<int, std::less<int>, std::allocator<long> > ms; +} diff --git a/test/std/containers/associative/multiset/scary.pass.cpp b/test/std/containers/associative/multiset/scary.pass.cpp index f5ee32714e86..bc4328b5332b 100644 --- a/test/std/containers/associative/multiset/scary.pass.cpp +++ b/test/std/containers/associative/multiset/scary.pass.cpp @@ -21,4 +21,5 @@ int main() typedef std::multiset<int> M2; M2::iterator i; M1::iterator j = i; + ((void)j); } diff --git a/test/std/containers/associative/set/allocator_mismatch.fail.cpp b/test/std/containers/associative/set/allocator_mismatch.fail.cpp new file mode 100644 index 000000000000..6905d9344864 --- /dev/null +++ b/test/std/containers/associative/set/allocator_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <set> +// The container's value type must be the same as the allocator's value type + +#include <set> + +int main() +{ + std::set<int, std::less<int>, std::allocator<long> > s; +} diff --git a/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp b/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp index b9775eef0673..5e429adb6fc9 100644 --- a/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp +++ b/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp @@ -14,6 +14,10 @@ #include <array> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { diff --git a/test/std/containers/sequences/array/array.data/data.pass.cpp b/test/std/containers/sequences/array/array.data/data.pass.cpp index 08e4fd39d377..d7aed70c98ad 100644 --- a/test/std/containers/sequences/array/array.data/data.pass.cpp +++ b/test/std/containers/sequences/array/array.data/data.pass.cpp @@ -14,6 +14,10 @@ #include <array> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { diff --git a/test/std/containers/sequences/array/array.data/data_const.pass.cpp b/test/std/containers/sequences/array/array.data/data_const.pass.cpp index 8eb9762dcb89..58840e940899 100644 --- a/test/std/containers/sequences/array/array.data/data_const.pass.cpp +++ b/test/std/containers/sequences/array/array.data/data_const.pass.cpp @@ -14,6 +14,10 @@ #include <array> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { diff --git a/test/std/containers/sequences/array/array.fill/fill.pass.cpp b/test/std/containers/sequences/array/array.fill/fill.pass.cpp index 675f49500627..5bc42ceb89f3 100644 --- a/test/std/containers/sequences/array/array.fill/fill.pass.cpp +++ b/test/std/containers/sequences/array/array.fill/fill.pass.cpp @@ -14,6 +14,10 @@ #include <array> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { diff --git a/test/std/containers/sequences/array/array.size/size.pass.cpp b/test/std/containers/sequences/array/array.size/size.pass.cpp index fe5a0d5c8db0..a833fdc04715 100644 --- a/test/std/containers/sequences/array/array.size/size.pass.cpp +++ b/test/std/containers/sequences/array/array.size/size.pass.cpp @@ -14,6 +14,10 @@ #include <array> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { diff --git a/test/std/containers/sequences/array/array.special/swap.pass.cpp b/test/std/containers/sequences/array/array.special/swap.pass.cpp index 08e437739ee6..c1b0b235ab34 100644 --- a/test/std/containers/sequences/array/array.special/swap.pass.cpp +++ b/test/std/containers/sequences/array/array.special/swap.pass.cpp @@ -14,6 +14,10 @@ #include <array> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { diff --git a/test/std/containers/sequences/array/array.swap/swap.pass.cpp b/test/std/containers/sequences/array/array.swap/swap.pass.cpp index c7a4cb8df38c..651798e1e790 100644 --- a/test/std/containers/sequences/array/array.swap/swap.pass.cpp +++ b/test/std/containers/sequences/array/array.swap/swap.pass.cpp @@ -14,6 +14,10 @@ #include <array> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { diff --git a/test/std/containers/sequences/array/array.tuple/get.fail.cpp b/test/std/containers/sequences/array/array.tuple/get.fail.cpp index 4f4fbcf93af6..13323dd8e519 100644 --- a/test/std/containers/sequences/array/array.tuple/get.fail.cpp +++ b/test/std/containers/sequences/array/array.tuple/get.fail.cpp @@ -11,15 +11,31 @@ // template <size_t I, class T, size_t N> T& get(array<T, N>& a); +// Prevent -Warray-bounds from issuing a diagnostic when testing with clang verify. +#if defined(__clang__) +#pragma clang diagnostic ignored "-Warray-bounds" +#endif + #include <array> #include <cassert> +#include "test_macros.h" + +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { typedef double T; typedef std::array<T, 3> C; C c = {1, 2, 3.5}; - std::get<3>(c) = 5.5; // Can't get element 3! + std::get<3>(c) = 5.5; // expected-note {{requested here}} +#if TEST_STD_VER >= 11 + // expected-error@array:* {{static_assert failed "Index out of bounds in std::get<> (std::array)"}} +#else + // expected-error@array:* {{implicit instantiation of undefined template '__static_assert_test<false>'}} +#endif } } diff --git a/test/std/containers/sequences/array/array.tuple/get.pass.cpp b/test/std/containers/sequences/array/array.tuple/get.pass.cpp index d9e242cd420b..4f210c4f762e 100644 --- a/test/std/containers/sequences/array/array.tuple/get.pass.cpp +++ b/test/std/containers/sequences/array/array.tuple/get.pass.cpp @@ -14,12 +14,19 @@ #include <array> #include <cassert> -#if __cplusplus > 201103L +#include "test_macros.h" + +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + + +#if TEST_STD_VER > 11 struct S { std::array<int, 3> a; int k; constexpr S() : a{1,2,3}, k(std::get<2>(a)) {} - }; +}; constexpr std::array<int, 2> getArr () { return { 3, 4 }; } #endif @@ -35,7 +42,7 @@ int main() assert(c[1] == 5.5); assert(c[2] == 3.5); } -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 { typedef double T; typedef std::array<T, 3> C; diff --git a/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp b/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp index 1cbdfa4ff393..04606bf6cf73 100644 --- a/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp +++ b/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp @@ -14,6 +14,12 @@ #include <array> #include <cassert> +#include "test_macros.h" + +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { @@ -24,7 +30,7 @@ int main() assert(std::get<1>(c) == 2); assert(std::get<2>(c) == 3.5); } -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 { typedef double T; typedef std::array<T, 3> C; diff --git a/test/std/containers/sequences/array/array.tuple/get_const_rv.pass.cpp b/test/std/containers/sequences/array/array.tuple/get_const_rv.pass.cpp new file mode 100644 index 000000000000..a22c91a4de47 --- /dev/null +++ b/test/std/containers/sequences/array/array.tuple/get_const_rv.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <array> + +// template <size_t I, class T, size_t N> const T&& get(const array<T, N>&& a); + +// UNSUPPORTED: c++98, c++03 + +#include <array> +#include <memory> +#include <type_traits> +#include <utility> +#include <cassert> + +#include "test_macros.h" + +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + +int main() +{ + + { + typedef std::unique_ptr<double> T; + typedef std::array<T, 1> C; + const C c = {std::unique_ptr<double>(new double(3.5))}; + static_assert(std::is_same<const T&&, decltype(std::get<0>(std::move(c)))>::value, ""); + static_assert(noexcept(std::get<0>(std::move(c))), ""); + const T&& t = std::get<0>(std::move(c)); + assert(*t == 3.5); + } + +#if TEST_STD_VER > 11 + { + typedef double T; + typedef std::array<T, 3> C; + constexpr const C c = {1, 2, 3.5}; + static_assert(std::get<0>(std::move(c)) == 1, ""); + static_assert(std::get<1>(std::move(c)) == 2, ""); + static_assert(std::get<2>(std::move(c)) == 3.5, ""); + } +#endif +} diff --git a/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp b/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp index 8eec3ceff514..72ef49b157f6 100644 --- a/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp +++ b/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp @@ -11,14 +11,20 @@ // template <size_t I, class T, size_t N> T&& get(array<T, N>&& a); +// UNSUPPORTED: c++98, c++03 + #include <array> #include <memory> #include <utility> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { typedef std::unique_ptr<double> T; typedef std::array<T, 1> C; @@ -26,5 +32,4 @@ int main() T t = std::get<0>(std::move(c)); assert(*t == 3.5); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/test/std/containers/sequences/array/at.pass.cpp b/test/std/containers/sequences/array/at.pass.cpp index b5cf8a5aaa8f..5cb89dfeeb9a 100644 --- a/test/std/containers/sequences/array/at.pass.cpp +++ b/test/std/containers/sequences/array/at.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <array> // reference operator[] (size_type) @@ -17,6 +18,12 @@ #include <array> #include <cassert> +#include "test_macros.h" + +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { @@ -27,7 +34,7 @@ int main() assert(r1 == 1); r1 = 5.5; assert(c.front() == 5.5); - + C::reference r2 = c.at(2); assert(r2 == 3.5); r2 = 7.5; @@ -50,7 +57,7 @@ int main() catch (const std::out_of_range &) {} } -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 { typedef double T; typedef std::array<T, 3> C; diff --git a/test/std/containers/sequences/array/begin.pass.cpp b/test/std/containers/sequences/array/begin.pass.cpp index 9cba0d6fceb0..b12ffc851b84 100644 --- a/test/std/containers/sequences/array/begin.pass.cpp +++ b/test/std/containers/sequences/array/begin.pass.cpp @@ -14,6 +14,10 @@ #include <array> #include <cassert> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { @@ -27,6 +31,4 @@ int main() *i = 5.5; assert(c[0] == 5.5); } - { - } } diff --git a/test/std/containers/sequences/array/front_back.pass.cpp b/test/std/containers/sequences/array/front_back.pass.cpp index 45a963b9947d..bccaade986ea 100644 --- a/test/std/containers/sequences/array/front_back.pass.cpp +++ b/test/std/containers/sequences/array/front_back.pass.cpp @@ -17,6 +17,12 @@ #include <array> #include <cassert> +#include "test_macros.h" + +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { @@ -45,12 +51,12 @@ int main() assert(r2 == 3.5); } -#if _LIBCPP_STD_VER > 11 +#if TEST_STD_VER > 11 { typedef double T; typedef std::array<T, 3> C; constexpr C c = {1, 2, 3.5}; - + constexpr T t1 = c.front(); static_assert (t1 == 1, ""); diff --git a/test/std/containers/sequences/array/indexing.pass.cpp b/test/std/containers/sequences/array/indexing.pass.cpp index e4dda0dc5cfd..5ccb0b487b95 100644 --- a/test/std/containers/sequences/array/indexing.pass.cpp +++ b/test/std/containers/sequences/array/indexing.pass.cpp @@ -17,6 +17,12 @@ #include <array> #include <cassert> +#include "test_macros.h" + +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { @@ -42,13 +48,13 @@ int main() C::const_reference r2 = c[2]; assert(r2 == 3.5); } - -#if _LIBCPP_STD_VER > 11 + +#if TEST_STD_VER > 11 { typedef double T; typedef std::array<T, 3> C; constexpr C c = {1, 2, 3.5}; - + constexpr T t1 = c[0]; static_assert (t1 == 1, ""); diff --git a/test/std/containers/sequences/deque/allocator_mismatch.fail.cpp b/test/std/containers/sequences/deque/allocator_mismatch.fail.cpp new file mode 100644 index 000000000000..9223c1ecddcb --- /dev/null +++ b/test/std/containers/sequences/deque/allocator_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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> +// The container's value type must be the same as the allocator's value type + +#include <deque> + +int main() +{ + std::deque<int, std::allocator<long> > d; +} diff --git a/test/std/containers/sequences/deque/deque.capacity/resize_size.pass.cpp b/test/std/containers/sequences/deque/deque.capacity/resize_size.pass.cpp index 522f839973db..84f04f9d52da 100644 --- a/test/std/containers/sequences/deque/deque.capacity/resize_size.pass.cpp +++ b/test/std/containers/sequences/deque/deque.capacity/resize_size.pass.cpp @@ -14,6 +14,7 @@ #include <deque> #include <cassert> +#include "test_macros.h" #include "min_allocator.h" template <class C> @@ -58,7 +59,6 @@ template <class C> void testN(int start, int N, int M) { - typedef typename C::const_iterator CI; C c1 = make<C>(N, start); test(c1, M); } @@ -73,7 +73,7 @@ int main() for (int k = 0; k < N; ++k) testN<std::deque<int> >(rng[i], rng[j], rng[k]); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); diff --git a/test/std/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp b/test/std/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp index 9eb514ba92f7..2bf2423fb9af 100644 --- a/test/std/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp +++ b/test/std/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp @@ -14,6 +14,7 @@ #include <deque> #include <cassert> +#include "test_macros.h" #include "min_allocator.h" template <class C> @@ -58,7 +59,6 @@ template <class C> void testN(int start, int N, int M) { - typedef typename C::const_iterator CI; C c1 = make<C>(N, start); test(c1, M, -10); } @@ -73,7 +73,7 @@ int main() for (int k = 0; k < N; ++k) testN<std::deque<int> >(rng[i], rng[j], rng[k]); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); diff --git a/test/std/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp b/test/std/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp index fb00069f33b6..0cf0387211d3 100644 --- a/test/std/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp +++ b/test/std/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp @@ -14,6 +14,7 @@ #include <deque> #include <cassert> +#include "test_macros.h" #include "min_allocator.h" template <class C> @@ -51,7 +52,6 @@ template <class C> void testN(int start, int N) { - typedef typename C::const_iterator CI; C c1 = make<C>(N, start); test(c1); } @@ -65,7 +65,7 @@ int main() for (int j = 0; j < N; ++j) testN<std::deque<int> >(rng[i], rng[j]); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); diff --git a/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp b/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp index 51a37cc33b7a..6507f58e1194 100644 --- a/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp +++ b/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp @@ -15,6 +15,7 @@ #include <deque> #include <cassert> +#include "test_macros.h" #include "test_iterators.h" #include "min_allocator.h" @@ -44,7 +45,6 @@ template <class C> void test(C& c1, const C& c2) { - std::size_t c1_osize = c1.size(); c1.assign(c2.begin(), c2.end()); assert(distance(c1.begin(), c1.end()) == c1.size()); assert(c1 == c2); @@ -54,8 +54,6 @@ template <class C> void testN(int start, int N, int M) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; C c1 = make<C>(N, start); C c2 = make<C>(M); test(c1, c2); @@ -67,7 +65,6 @@ testI(C& c1, const C& c2) { typedef typename C::const_iterator CI; typedef input_iterator<CI> ICI; - std::size_t c1_osize = c1.size(); c1.assign(ICI(c2.begin()), ICI(c2.end())); assert(distance(c1.begin(), c1.end()) == c1.size()); assert(c1 == c2); @@ -77,8 +74,6 @@ template <class C> void testNI(int start, int N, int M) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; C c1 = make<C>(N, start); C c2 = make<C>(M); testI(c1, c2); @@ -95,7 +90,7 @@ int main() testN<std::deque<int> >(rng[i], rng[j], rng[k]); testNI<std::deque<int> >(1500, 2000, 1000); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); diff --git a/test/std/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp b/test/std/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp index 3ab79a095fce..e00e0442d22e 100644 --- a/test/std/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp +++ b/test/std/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp @@ -14,6 +14,7 @@ #include <deque> #include <cassert> +#include "test_macros.h" #include "test_iterators.h" #include "min_allocator.h" @@ -44,7 +45,6 @@ void test(C& c1, int size, int v) { typedef typename C::const_iterator CI; - std::size_t c1_osize = c1.size(); c1.assign(size, v); assert(c1.size() == size); assert(distance(c1.begin(), c1.end()) == c1.size()); @@ -56,8 +56,6 @@ template <class C> void testN(int start, int N, int M) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; C c1 = make<C>(N, start); test(c1, M, -10); } @@ -72,7 +70,7 @@ int main() for (int k = 0; k < N; ++k) testN<std::deque<int> >(rng[i], rng[j], rng[k]); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); diff --git a/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp index 7a0a2512ee2f..713f2159e598 100644 --- a/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp +++ b/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp @@ -11,13 +11,14 @@ // template <class... Args> iterator emplace(const_iterator p, Args&&... args); +// UNSUPPORTED: c++98, c++03 + #include <deque> #include <cassert> #include "../../../Emplaceable.h" #include "min_allocator.h" -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class C> C @@ -45,7 +46,6 @@ template <class C> void test(int P, C& c1) { - typedef typename C::iterator I; typedef typename C::const_iterator CI; std::size_t c1_osize = c1.size(); CI i = c1.emplace(c1.begin() + P, Emplaceable(1, 2.5)); @@ -59,8 +59,6 @@ template <class C> void testN(int start, int N) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; for (int i = 0; i <= 3; ++i) { if (0 <= i && i <= N) @@ -87,11 +85,9 @@ testN(int start, int N) } } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES int main() { -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); @@ -99,7 +95,6 @@ int main() for (int j = 0; j < N; ++j) testN<std::deque<Emplaceable> >(rng[i], rng[j]); } -#if __cplusplus >= 201103L { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); @@ -107,6 +102,4 @@ int main() for (int j = 0; j < N; ++j) testN<std::deque<Emplaceable, min_allocator<Emplaceable>> >(rng[i], rng[j]); } -#endif -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp index ecb95d72a21e..fbe3cb69ccdd 100644 --- a/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp +++ b/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp @@ -17,6 +17,7 @@ #include <deque> #include <cassert> +#include "test_macros.h" #include "test_iterators.h" #include "MoveOnly.h" #include "../../../stack_allocator.h" @@ -49,7 +50,6 @@ void test(int P, const C& c0, const C& c2) { { - typedef typename C::iterator I; typedef typename C::const_iterator CI; typedef input_iterator<CI> BCI; C c1 = c0; @@ -67,7 +67,6 @@ test(int P, const C& c0, const C& c2) assert(*i == j); } { - typedef typename C::iterator I; typedef typename C::const_iterator CI; typedef forward_iterator<CI> BCI; C c1 = c0; @@ -85,7 +84,6 @@ test(int P, const C& c0, const C& c2) assert(*i == j); } { - typedef typename C::iterator I; typedef typename C::const_iterator CI; typedef bidirectional_iterator<CI> BCI; C c1 = c0; @@ -108,8 +106,6 @@ template <class C> void testN(int start, int N, int M) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; for (int i = 0; i <= 3; ++i) { if (0 <= i && i <= N) @@ -170,7 +166,6 @@ template <class C> void testI(int P, C& c1, const C& c2) { - typedef typename C::iterator I; typedef typename C::const_iterator CI; typedef input_iterator<CI> ICI; std::size_t c1_osize = c1.size(); @@ -191,8 +186,6 @@ template <class C> void testNI(int start, int N, int M) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; for (int i = 0; i <= 3; ++i) { if (0 <= i && i <= N) @@ -244,7 +237,7 @@ template <class C> void test_move() { -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if TEST_STD_VER >= 11 C c; typedef typename C::const_iterator CI; { @@ -263,7 +256,7 @@ test_move() j = 0; for (CI i = c.begin(); i != c.end(); ++i, ++j) assert(*i == MoveOnly(j)); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif } int main() @@ -276,11 +269,11 @@ int main() for (int k = 0; k < N; ++k) testN<std::deque<int> >(rng[i], rng[j], rng[k]); testNI<std::deque<int> >(1500, 2000, 1000); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if TEST_STD_VER >= 11 test_move<std::deque<MoveOnly, stack_allocator<MoveOnly, 2000> > >(); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); diff --git a/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp index b7e73f265028..3c7b0fef28b4 100644 --- a/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp +++ b/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp @@ -11,13 +11,14 @@ // iterator insert (const_iterator p, value_type&& v); +// UNSUPPORTED: c++98, c++03 + #include <deque> #include <cassert> #include "MoveOnly.h" #include "min_allocator.h" -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class C> C @@ -45,7 +46,6 @@ template <class C> void test(int P, C& c1, int x) { - typedef typename C::iterator I; typedef typename C::const_iterator CI; std::size_t c1_osize = c1.size(); CI i = c1.insert(c1.begin() + P, MoveOnly(x)); @@ -65,8 +65,6 @@ template <class C> void testN(int start, int N) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; for (int i = 0; i <= 3; ++i) { if (0 <= i && i <= N) @@ -93,11 +91,8 @@ testN(int start, int N) } } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - int main() { -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); @@ -105,7 +100,6 @@ int main() for (int j = 0; j < N; ++j) testN<std::deque<MoveOnly> >(rng[i], rng[j]); } -#if __cplusplus >= 201103L { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); @@ -113,6 +107,4 @@ int main() for (int j = 0; j < N; ++j) testN<std::deque<MoveOnly, min_allocator<MoveOnly>> >(rng[i], rng[j]); } -#endif -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp index 2737dfba7739..0efe3b44c604 100644 --- a/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp +++ b/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp @@ -16,6 +16,7 @@ #include <deque> #include <cassert> +#include "test_macros.h" #include "min_allocator.h" template <class C> @@ -44,7 +45,6 @@ template <class C> void test(int P, C& c1, int size, int x) { - typedef typename C::iterator I; typedef typename C::const_iterator CI; std::size_t c1_osize = c1.size(); CI i = c1.insert(c1.begin() + P, size, x); @@ -64,8 +64,6 @@ template <class C> void testN(int start, int N, int M) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; for (int i = 0; i <= 3; ++i) { if (0 <= i && i <= N) @@ -145,7 +143,7 @@ int main() testN<std::deque<int> >(rng[i], rng[j], rng[k]); self_reference_test<std::deque<int> >(); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); diff --git a/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp index fbbaad4f89e5..04c4ca4f7b26 100644 --- a/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp +++ b/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp @@ -14,6 +14,7 @@ #include <deque> #include <cassert> +#include "test_macros.h" #include "min_allocator.h" template <class C> @@ -42,7 +43,6 @@ template <class C> void test(int P, C& c1, int x) { - typedef typename C::iterator I; typedef typename C::const_iterator CI; std::size_t c1_osize = c1.size(); CI i = c1.insert(c1.begin() + P, x); @@ -62,8 +62,6 @@ template <class C> void testN(int start, int N) { - typedef typename C::iterator I; - typedef typename C::const_iterator CI; for (int i = 0; i <= 3; ++i) { if (0 <= i && i <= N) @@ -126,7 +124,7 @@ int main() testN<std::deque<int> >(rng[i], rng[j]); self_reference_test<std::deque<int> >(); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; const int N = sizeof(rng)/sizeof(rng[0]); diff --git a/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp index 8ad6b53f1b5f..b37e961e442f 100644 --- a/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp +++ b/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <deque> // void push_back(const value_type& x); diff --git a/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp index e01b2a224ffd..b4caa947aed8 100644 --- a/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp +++ b/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <deque> // void push_front(const value_type& x); diff --git a/test/std/containers/sequences/forwardlist/allocator_mismatch.fail.cpp b/test/std/containers/sequences/forwardlist/allocator_mismatch.fail.cpp new file mode 100644 index 000000000000..b53075d033bc --- /dev/null +++ b/test/std/containers/sequences/forwardlist/allocator_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <forward_list> +// The container's value type must be the same as the allocator's value type + +#include <forward_list> + +int main() +{ + std::forward_list<int, std::allocator<long> > fl; +} diff --git a/test/std/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp b/test/std/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp index 8341f7ba0cb2..88ecb7540951 100644 --- a/test/std/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp +++ b/test/std/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp @@ -24,7 +24,7 @@ int main() #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES { typedef MoveOnly T; - typedef test_allocator<int> A; + typedef test_allocator<T> A; typedef std::forward_list<T, A> C; T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; typedef std::move_iterator<T*> I; @@ -39,7 +39,7 @@ int main() } { typedef MoveOnly T; - typedef other_allocator<int> A; + typedef other_allocator<T> A; typedef std::forward_list<T, A> C; T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; typedef std::move_iterator<T*> I; @@ -55,7 +55,7 @@ int main() #if __cplusplus >= 201103L { typedef MoveOnly T; - typedef min_allocator<int> A; + typedef min_allocator<T> A; typedef std::forward_list<T, A> C; T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; typedef std::move_iterator<T*> I; diff --git a/test/std/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp b/test/std/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp index 6bb575ef80f1..3f0e45af1f0b 100644 --- a/test/std/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp +++ b/test/std/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp @@ -24,7 +24,7 @@ int main() #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES { typedef MoveOnly T; - typedef test_allocator<int> A; + typedef test_allocator<T> A; typedef std::forward_list<T, A> C; T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; typedef std::move_iterator<T*> I; @@ -39,7 +39,7 @@ int main() } { typedef MoveOnly T; - typedef test_allocator<int> A; + typedef test_allocator<T> A; typedef std::forward_list<T, A> C; T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; typedef std::move_iterator<T*> I; @@ -55,7 +55,7 @@ int main() #if __cplusplus >= 201103L { typedef MoveOnly T; - typedef min_allocator<int> A; + typedef min_allocator<T> A; typedef std::forward_list<T, A> C; T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; typedef std::move_iterator<T*> I; diff --git a/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_exception_safety.pass.cpp b/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_exception_safety.pass.cpp index 43c62eb00cbf..b501347e7893 100644 --- a/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_exception_safety.pass.cpp +++ b/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_exception_safety.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <forward_list> // void push_front(const value_type& x); diff --git a/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp b/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp index 296ffcd6955d..349a3872d754 100644 --- a/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp +++ b/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp @@ -15,6 +15,7 @@ #include <cassert> #include <iterator> +#include "test_macros.h" #include "min_allocator.h" typedef int T; @@ -44,7 +45,6 @@ tests(const C& c, int p, int f) { typename C::const_iterator i = c.begin(); int n = 0; - int d = 1; if (p == f || p == f+1) { for (n = 0; n < size_t1; ++n, ++i) @@ -106,7 +106,7 @@ int main() } } } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { // splicing different containers typedef std::forward_list<T, min_allocator<T>> C; diff --git a/test/std/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp b/test/std/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp index ca673b583683..9f01fed66465 100644 --- a/test/std/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp +++ b/test/std/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp @@ -22,12 +22,12 @@ #include <algorithm> #include <cassert> +#include "test_macros.h" #include "min_allocator.h" template <class C> void test(int N, int M) { - typedef typename C::value_type T; C c1; for (int i = 0; i < N; ++i) c1.push_front(i); @@ -52,7 +52,7 @@ int main() for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) test<std::forward_list<int> >(i, j); -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) test<std::forward_list<int, min_allocator<int>> >(i, j); diff --git a/test/std/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp b/test/std/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp index 42e245d007b0..e65e064ffdaf 100644 --- a/test/std/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp +++ b/test/std/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp @@ -30,12 +30,12 @@ #include <algorithm> #include <cassert> +#include "test_macros.h" #include "min_allocator.h" template <class C> void test(int N, int M) { - typedef typename C::value_type T; C c1; for (int i = 0; i < N; ++i) c1.push_front(i); @@ -57,7 +57,7 @@ int main() for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) test<std::forward_list<int> >(i, j); -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) test<std::forward_list<int, min_allocator<int>> >(i, j); diff --git a/test/std/containers/sequences/list/allocator_mismatch.fail.cpp b/test/std/containers/sequences/list/allocator_mismatch.fail.cpp new file mode 100644 index 000000000000..3490d106a60c --- /dev/null +++ b/test/std/containers/sequences/list/allocator_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <list> +// The container's value type must be the same as the allocator's value type + +#include <list> + +int main() +{ + std::list<int, std::allocator<long> > l; +} diff --git a/test/std/containers/sequences/list/incomplete_type.pass.cpp b/test/std/containers/sequences/list/incomplete_type.pass.cpp new file mode 100644 index 000000000000..adfb4d45fc81 --- /dev/null +++ b/test/std/containers/sequences/list/incomplete_type.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <list> + +// Check that std::list and it's iterators can be instantiated with an incomplete +// type. + +#include <list> + +struct A { + std::list<A> l; + std::list<A>::iterator it; + std::list<A>::const_iterator cit; + std::list<A>::reverse_iterator rit; + std::list<A>::const_reverse_iterator crit; +}; + +int main() { + A a; +} diff --git a/test/std/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp b/test/std/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp index a7f1917ab856..736b9baae746 100644 --- a/test/std/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp +++ b/test/std/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <list> // template <InputIterator Iter> diff --git a/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp b/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp index eeb74b83e509..c0f6ed198751 100644 --- a/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp +++ b/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <list> // iterator insert(const_iterator position, size_type n, const value_type& x); diff --git a/test/std/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp b/test/std/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp index 406e93a376a1..1aacb63e4a70 100644 --- a/test/std/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp +++ b/test/std/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <list> // iterator insert(const_iterator position, const value_type& x); diff --git a/test/std/containers/sequences/list/list.modifiers/push_back_exception_safety.pass.cpp b/test/std/containers/sequences/list/list.modifiers/push_back_exception_safety.pass.cpp index 9d3c05e26b1c..8d16142defc0 100644 --- a/test/std/containers/sequences/list/list.modifiers/push_back_exception_safety.pass.cpp +++ b/test/std/containers/sequences/list/list.modifiers/push_back_exception_safety.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <list> // void push_back(const value_type& x); diff --git a/test/std/containers/sequences/list/list.modifiers/push_front_exception_safety.pass.cpp b/test/std/containers/sequences/list/list.modifiers/push_front_exception_safety.pass.cpp index 6609005262eb..aafcceecd471 100644 --- a/test/std/containers/sequences/list/list.modifiers/push_front_exception_safety.pass.cpp +++ b/test/std/containers/sequences/list/list.modifiers/push_front_exception_safety.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <list> // void push_front(const value_type& x); diff --git a/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp b/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp index b580eb4ae3b0..4dd871c9447e 100644 --- a/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp +++ b/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp @@ -28,6 +28,32 @@ struct some_alloc some_alloc(const some_alloc&); }; +template <class T> +struct some_alloc2 +{ + typedef T value_type; + + some_alloc2() {} + some_alloc2(const some_alloc2&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_move_assignment; + typedef std::true_type is_always_equal; +}; + +template <class T> +struct some_alloc3 +{ + typedef T value_type; + + some_alloc3() {} + some_alloc3(const some_alloc3&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_move_assignment; + typedef std::false_type is_always_equal; +}; + int main() { #if __has_feature(cxx_noexcept) @@ -45,7 +71,22 @@ int main() } { typedef std::vector<bool, some_alloc<bool>> C; +#if TEST_STD_VER > 14 + static_assert( std::is_nothrow_move_assignable<C>::value, ""); +#else static_assert(!std::is_nothrow_move_assignable<C>::value, ""); +#endif + } +#if TEST_STD_VER > 14 + { // POCMA false, is_always_equal true + typedef std::vector<bool, some_alloc2<bool>> C; + static_assert( std::is_nothrow_move_assignable<C>::value, ""); } + { // POCMA false, is_always_equal false + typedef std::vector<bool, some_alloc3<bool>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } +#endif + #endif } diff --git a/test/std/containers/sequences/vector/allocator_mismatch.fail.cpp b/test/std/containers/sequences/vector/allocator_mismatch.fail.cpp new file mode 100644 index 000000000000..65fdb63ee6a0 --- /dev/null +++ b/test/std/containers/sequences/vector/allocator_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <vector> +// The container's value type must be the same as the allocator's value type + +#include <vector> + +int main() +{ + std::vector<int, std::allocator<long> > v; +} diff --git a/test/std/containers/sequences/vector/asan.pass.cpp b/test/std/containers/sequences/vector/asan.pass.cpp deleted file mode 100644 index 86c02b295624..000000000000 --- a/test/std/containers/sequences/vector/asan.pass.cpp +++ /dev/null @@ -1,52 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// <vector> - -// reference operator[](size_type n); - -#include <vector> -#include <cassert> -#include <cstdlib> - -#include "min_allocator.h" -#include "asan_testing.h" - -#ifndef _LIBCPP_HAS_NO_ASAN -extern "C" void __asan_set_error_exit_code(int); - -int main() -{ -#if __cplusplus >= 201103L - { - typedef int T; - typedef std::vector<T, min_allocator<T>> C; - const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - C c(std::begin(t), std::end(t)); - c.reserve(2*c.size()); - T foo = c[c.size()]; // bad, but not caught by ASAN - } -#endif - - __asan_set_error_exit_code(0); - { - typedef int T; - typedef std::vector<T> C; - const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - C c(std::begin(t), std::end(t)); - c.reserve(2*c.size()); - assert(is_contiguous_container_asan_correct(c)); - assert(!__sanitizer_verify_contiguous_container ( c.data(), c.data() + 1, c.data() + c.capacity())); - T foo = c[c.size()]; // should trigger ASAN - assert(false); // if we got here, ASAN didn't trigger - } -} -#else -int main () { return 0; } -#endif diff --git a/test/std/containers/sequences/vector/asan_throw.pass.cpp b/test/std/containers/sequences/vector/asan_throw.pass.cpp deleted file mode 100644 index c100da1aade7..000000000000 --- a/test/std/containers/sequences/vector/asan_throw.pass.cpp +++ /dev/null @@ -1,232 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// Test asan vector annotations with a class that throws in a CTOR. - -#include <vector> -#include <cassert> - -#include "asan_testing.h" - -class X { -public: - X(const X &x) { Init(x.a); } - X(char arg) { Init(arg); } - X() { Init(42); } - X &operator=(const X &x) { - Init(x.a); - return *this; - } - void Init(char arg) { - if (arg == 42) - throw 0; - if (arg == 66) - arg = 42; - a = arg; - } - char get() const { return a; } - void set(char arg) { a = arg; } - -private: - char a; -}; - -class ThrowOnCopy { -public: - ThrowOnCopy() : should_throw(false) {} - explicit ThrowOnCopy(bool should_throw) : should_throw(should_throw) {} - - ThrowOnCopy(ThrowOnCopy const & other) - : should_throw(other.should_throw) - { - if (should_throw) { - throw 0; - } - } - - bool should_throw; -}; - -void test_push_back() { - std::vector<X> v; - v.reserve(2); - v.push_back(X(2)); - assert(v.size() == 1); - try { - v.push_back(X(66)); - assert(0); - } catch (int e) { - assert(v.size() == 1); - } - assert(v.size() == 1); - assert(is_contiguous_container_asan_correct(v)); -} - -void test_emplace_back() { -#ifndef _LIBCPP_HAS_NO_VARIADICS - std::vector<X> v; - v.reserve(2); - v.push_back(X(2)); - assert(v.size() == 1); - try { - v.emplace_back(42); - assert(0); - } catch (int e) { - assert(v.size() == 1); - } - assert(v.size() == 1); - assert(is_contiguous_container_asan_correct(v)); -#endif // _LIBCPP_HAS_NO_VARIADICS -} - -void test_insert_range() { - std::vector<X> v; - v.reserve(4); - v.push_back(X(1)); - v.push_back(X(2)); - assert(v.size() == 2); - assert(v.capacity() >= 4); - try { - char a[2] = {21, 42}; - v.insert(v.end(), a, a + 2); - assert(0); - } catch (int e) { - assert(v.size() == 3); - } - assert(v.size() == 3); - assert(is_contiguous_container_asan_correct(v)); -} - -void test_insert() { - std::vector<X> v; - v.reserve(3); - v.insert(v.end(), X(1)); - v.insert(v.begin(), X(2)); - assert(v.size() == 2); - try { - v.insert(v.end(), X(66)); - assert(0); - } catch (int e) { - assert(v.size() == 2); - } - assert(v.size() == 2); - assert(is_contiguous_container_asan_correct(v)); -} - -void test_emplace() { -#ifndef _LIBCPP_HAS_NO_VARIADICS - std::vector<X> v; - v.reserve(3); - v.insert(v.end(), X(1)); - v.insert(v.begin(), X(2)); - assert(v.size() == 2); - try { - v.emplace(v.end(), 42); - assert(0); - } catch (int e) { - assert(v.size() == 2); - } - assert(v.size() == 2); - assert(is_contiguous_container_asan_correct(v)); -#endif // _LIBCPP_HAS_NO_VARIADICS -} - -void test_insert_range2() { - std::vector<X> v; - v.reserve(4); - v.insert(v.end(), X(1)); - v.insert(v.begin(), X(2)); - assert(v.size() == 2); - assert(v.capacity() >= 4); - try { - char a[2] = {10, 42}; - v.insert(v.begin(), a, a + 2); - assert(0); - } catch (int e) { - assert(v.size() <= 4); - assert(is_contiguous_container_asan_correct(v)); - return; - } - assert(0); -} - -void test_insert_n() { - std::vector<X> v; - v.reserve(10); - v.insert(v.end(), X(1)); - v.insert(v.begin(), X(2)); - assert(v.size() == 2); - try { - v.insert(v.begin(), 1, X(66)); - assert(0); - } catch (int e) { - assert(v.size() <= 3); - assert(is_contiguous_container_asan_correct(v)); - return; - } - assert(0); -} - - -void test_insert_n2() { - std::vector<ThrowOnCopy> v(10); - v.reserve(100); - assert(v.size() == 10); - v[6].should_throw = true; - try { - v.insert(v.cbegin(), 5, ThrowOnCopy()); - assert(0); - } catch (int e) { - assert(v.size() == 11); - assert(is_contiguous_container_asan_correct(v)); - return; - } - assert(0); -} - -void test_resize() { - std::vector<X> v; - v.reserve(3); - v.push_back(X(0)); - try { - v.resize(3); - assert(0); - } catch (int e) { - assert(v.size() == 1); - } - assert(v.size() == 1); - assert(is_contiguous_container_asan_correct(v)); -} - -void test_resize_param() { - std::vector<X> v; - v.reserve(3); - v.push_back(X(0)); - try { - v.resize(3, X(66)); - assert(0); - } catch (int e) { - assert(v.size() == 1); - } - assert(v.size() == 1); - assert(is_contiguous_container_asan_correct(v)); -} - -int main() { - test_push_back(); - test_emplace_back(); - test_insert_range(); - test_insert(); - test_emplace(); - test_insert_range2(); - test_insert_n(); - test_insert_n2(); - test_resize(); - test_resize_param(); -} diff --git a/test/std/containers/sequences/vector/vector.cons/move_assign_noexcept.pass.cpp b/test/std/containers/sequences/vector/vector.cons/move_assign_noexcept.pass.cpp index 1c4a4f7c9282..c09224497966 100644 --- a/test/std/containers/sequences/vector/vector.cons/move_assign_noexcept.pass.cpp +++ b/test/std/containers/sequences/vector/vector.cons/move_assign_noexcept.pass.cpp @@ -29,6 +29,33 @@ struct some_alloc some_alloc(const some_alloc&); }; +template <class T> +struct some_alloc2 +{ + typedef T value_type; + + some_alloc2() {} + some_alloc2(const some_alloc2&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_move_assignment; + typedef std::true_type is_always_equal; +}; + +template <class T> +struct some_alloc3 +{ + typedef T value_type; + + some_alloc3() {} + some_alloc3(const some_alloc3&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_move_assignment; + typedef std::false_type is_always_equal; +}; + + int main() { #if __has_feature(cxx_noexcept) @@ -46,7 +73,24 @@ int main() } { typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C; + // In C++17, move assignment for allocators are not allowed to throw +#if TEST_STD_VER > 14 + static_assert( std::is_nothrow_move_assignable<C>::value, ""); +#else + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); +#endif + } + +#if TEST_STD_VER > 14 + { // POCMA false, is_always_equal true + typedef std::vector<MoveOnly, some_alloc2<MoveOnly>> C; + static_assert( std::is_nothrow_move_assignable<C>::value, ""); + } + { // POCMA false, is_always_equal false + typedef std::vector<MoveOnly, some_alloc3<MoveOnly>> C; static_assert(!std::is_nothrow_move_assignable<C>::value, ""); } #endif + +#endif } diff --git a/test/std/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp b/test/std/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp index 6615a25a620f..785225357d4b 100644 --- a/test/std/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp +++ b/test/std/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <vector> // void push_back(const value_type& x); diff --git a/test/std/containers/unord/unord.map/allocator_mismatch.fail.cpp b/test/std/containers/unord/unord.map/allocator_mismatch.fail.cpp new file mode 100644 index 000000000000..39fcb11add40 --- /dev/null +++ b/test/std/containers/unord/unord.map/allocator_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> +// The container's value type must be the same as the allocator's value type + +#include <unordered_map> + +int main() +{ + std::unordered_map<int, int, std::hash<int>, std::less<int>, std::allocator<long> > m; +} diff --git a/test/std/containers/unord/unord.map/bucket_count.pass.cpp b/test/std/containers/unord/unord.map/bucket_count.pass.cpp index d3e80d86379a..bc3733742600 100644 --- a/test/std/containers/unord/unord.map/bucket_count.pass.cpp +++ b/test/std/containers/unord/unord.map/bucket_count.pass.cpp @@ -19,20 +19,18 @@ #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[] = { diff --git a/test/std/containers/unord/unord.map/compare.pass.cpp b/test/std/containers/unord/unord.map/compare.pass.cpp index 8979a3a34ad6..ea6d02f5fcbc 100644 --- a/test/std/containers/unord/unord.map/compare.pass.cpp +++ b/test/std/containers/unord/unord.map/compare.pass.cpp @@ -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); } diff --git a/test/std/containers/unord/unord.map/load_factor.pass.cpp b/test/std/containers/unord/unord.map/load_factor.pass.cpp index 472e41abf6e0..b25c019688a6 100644 --- a/test/std/containers/unord/unord.map/load_factor.pass.cpp +++ b/test/std/containers/unord/unord.map/load_factor.pass.cpp @@ -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); } diff --git a/test/std/containers/unord/unord.map/max_bucket_count.pass.cpp b/test/std/containers/unord/unord.map/max_bucket_count.pass.cpp index b4ca8eb04472..08f014da2f49 100644 --- a/test/std/containers/unord/unord.map/max_bucket_count.pass.cpp +++ b/test/std/containers/unord/unord.map/max_bucket_count.pass.cpp @@ -19,23 +19,20 @@ #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); } diff --git a/test/std/containers/unord/unord.map/max_load_factor.pass.cpp b/test/std/containers/unord/unord.map/max_load_factor.pass.cpp index 69fd70d2a172..b19a6e6cfa08 100644 --- a/test/std/containers/unord/unord.map/max_load_factor.pass.cpp +++ b/test/std/containers/unord/unord.map/max_load_factor.pass.cpp @@ -16,44 +16,37 @@ // 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); diff --git a/test/std/containers/unord/unord.map/rehash.pass.cpp b/test/std/containers/unord/unord.map/rehash.pass.cpp index 84ece2355511..e1a882c69ffd 100644 --- a/test/std/containers/unord/unord.map/rehash.pass.cpp +++ b/test/std/containers/unord/unord.map/rehash.pass.cpp @@ -22,6 +22,12 @@ #include "min_allocator.h" template <class C> +void rehash_postcondition(const C& c, size_t n) +{ + assert(c.bucket_count() >= c.size() / c.max_load_factor() && c.bucket_count() >= n); +} + +template <class C> void test(const C& c) { assert(c.size() == 4); @@ -49,13 +55,16 @@ int main() test(c); assert(c.bucket_count() >= 5); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 5); test(c); c.max_load_factor(2); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 3); test(c); c.rehash(31); + rehash_postcondition(c, 31); assert(c.bucket_count() == 31); test(c); } @@ -77,13 +86,16 @@ int main() test(c); assert(c.bucket_count() >= 5); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 5); test(c); c.max_load_factor(2); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 3); test(c); c.rehash(31); + rehash_postcondition(c, 31); assert(c.bucket_count() == 31); test(c); } diff --git a/test/std/containers/unord/unord.map/reserve.pass.cpp b/test/std/containers/unord/unord.map/reserve.pass.cpp index 48667cdc7f92..bef237f960af 100644 --- a/test/std/containers/unord/unord.map/reserve.pass.cpp +++ b/test/std/containers/unord/unord.map/reserve.pass.cpp @@ -31,6 +31,21 @@ void test(const C& c) assert(c.at(4) == "four"); } +void reserve_invariant(size_t n) // LWG #2156 +{ + for (size_t i = 0; i < n; ++i) + { + std::unordered_map<size_t, size_t> c; + c.reserve(n); + size_t buckets = c.bucket_count(); + for (size_t j = 0; j < i; ++j) + { + c[i] = i; + assert(buckets == c.bucket_count()); + } + } +} + int main() { { @@ -88,4 +103,5 @@ int main() test(c); } #endif + reserve_invariant(20); } diff --git a/test/std/containers/unord/unord.map/swap_member.pass.cpp b/test/std/containers/unord/unord.map/swap_member.pass.cpp index 8ab1eb6211b8..0f98b66aa401 100644 --- a/test/std/containers/unord/unord.map/swap_member.pass.cpp +++ b/test/std/containers/unord/unord.map/swap_member.pass.cpp @@ -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); diff --git a/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp b/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp index 18e6683011c8..1420204c5f76 100644 --- a/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp @@ -15,6 +15,8 @@ // unordered_map(unordered_map&& u); +// UNSUPPORTED: c++98, c++03 + #include <unordered_map> #include <string> #include <cassert> @@ -27,23 +29,12 @@ 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 } diff --git a/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp b/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp index 5fd9f9d6114a..04ce91f69917 100644 --- a/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +// XFAIL: libcpp-no-exceptions // <unordered_map> // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/clear.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/clear.pass.cpp index 9f320e949479..9f320e949479 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/clear.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/clear.pass.cpp diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/emplace.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/emplace.pass.cpp index 5de74d2e6c92..5de74d2e6c92 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/emplace.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/emplace.pass.cpp diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/emplace_hint.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/emplace_hint.pass.cpp index 21a4689658ae..21a4689658ae 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/emplace_hint.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/emplace_hint.pass.cpp diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_const_iter.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_const_iter.pass.cpp index dbb812974d46..803ecb5adfcb 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_const_iter.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_const_iter.pass.cpp @@ -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; diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_db1.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_db1.pass.cpp index 60b093553f18..60b093553f18 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_db1.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_db1.pass.cpp diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_db2.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_db2.pass.cpp index 05046f5dedc1..05046f5dedc1 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_db2.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_db2.pass.cpp diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db1.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_iter_db1.pass.cpp index 81a8d3de1576..81a8d3de1576 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db1.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_iter_db1.pass.cpp diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db2.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_iter_db2.pass.cpp index 4b103a0ad75c..4b103a0ad75c 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db2.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_iter_db2.pass.cpp diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db3.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_iter_db3.pass.cpp index 6ef1e07add1e..6ef1e07add1e 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db3.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_iter_db3.pass.cpp diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db4.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_iter_db4.pass.cpp index 1185ddf8fd4a..1185ddf8fd4a 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db4.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_iter_iter_db4.pass.cpp diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_key.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_key.pass.cpp index 0e8ef8b895a7..cdd19eb3459d 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_key.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_key.pass.cpp @@ -19,15 +19,16 @@ #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()) { diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_range.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_range.pass.cpp index f0664c3c3ffc..f0664c3c3ffc 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_range.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/erase_range.pass.cpp diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_const_lvalue.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_const_lvalue.pass.cpp index a16f097b4c01..a16f097b4c01 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_const_lvalue.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_const_lvalue.pass.cpp diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_hint_const_lvalue.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.pass.cpp index 981b8fb18a0a..981b8fb18a0a 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_hint_const_lvalue.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.pass.cpp diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_hint_rvalue.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_rvalue.pass.cpp index 1618c1019e1c..1618c1019e1c 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_hint_rvalue.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_rvalue.pass.cpp diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_init.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_init.pass.cpp index 81e8a468d83f..81e8a468d83f 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_init.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_init.pass.cpp diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_or_assign.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_or_assign.pass.cpp index 89929c856ec9..a4d8abc7d317 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_or_assign.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_or_assign.pass.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// UNSUPPORTED: c++03, c++11, c++14 +// UNSUPPORTED: c++98, c++03, c++11, c++14 // <unordered_map> @@ -22,12 +22,10 @@ // 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 diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_range.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_range.pass.cpp index fc44e7828ffa..fc44e7828ffa 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_range.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_range.pass.cpp diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_rvalue.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_rvalue.pass.cpp index f53dc6c7e97a..f53dc6c7e97a 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_rvalue.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_rvalue.pass.cpp diff --git a/test/std/containers/unord/unord.map/unorder.map.modifiers/try.emplace.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/try.emplace.pass.cpp index e6964ce947b5..eabcf2e85db2 100644 --- a/test/std/containers/unord/unord.map/unorder.map.modifiers/try.emplace.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/try.emplace.pass.cpp @@ -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 } diff --git a/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp b/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp index 7e04b8db117c..f3d51f6da275 100644 --- a/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp +++ b/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp @@ -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); diff --git a/test/std/containers/unord/unord.multimap/allocator_mismatch.fail.cpp b/test/std/containers/unord/unord.multimap/allocator_mismatch.fail.cpp new file mode 100644 index 000000000000..3c740950d04e --- /dev/null +++ b/test/std/containers/unord/unord.multimap/allocator_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <unordered_map> +// The container's value type must be the same as the allocator's value type + +#include <unordered_map> + +int main() +{ + std::unordered_multimap<int, int, std::hash<int>, std::less<int>, std::allocator<long> > m; +} diff --git a/test/std/containers/unord/unord.multimap/rehash.pass.cpp b/test/std/containers/unord/unord.multimap/rehash.pass.cpp index 1d99208596c1..d36dc42e262d 100644 --- a/test/std/containers/unord/unord.multimap/rehash.pass.cpp +++ b/test/std/containers/unord/unord.multimap/rehash.pass.cpp @@ -23,6 +23,12 @@ #include "min_allocator.h" template <class C> +void rehash_postcondition(const C& c, size_t n) +{ + assert(c.bucket_count() >= c.size() / c.max_load_factor() && c.bucket_count() >= n); +} + +template <class C> void test(const C& c) { assert(c.size() == 6); @@ -77,13 +83,16 @@ int main() test(c); assert(c.bucket_count() >= 7); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 7); test(c); c.max_load_factor(2); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 3); test(c); c.rehash(31); + rehash_postcondition(c, 31); assert(c.bucket_count() == 31); test(c); } @@ -105,13 +114,16 @@ int main() test(c); assert(c.bucket_count() >= 7); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 7); test(c); c.max_load_factor(2); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 3); test(c); c.rehash(31); + rehash_postcondition(c, 31); assert(c.bucket_count() == 31); test(c); } diff --git a/test/std/containers/unord/unord.multimap/reserve.pass.cpp b/test/std/containers/unord/unord.multimap/reserve.pass.cpp index 801c74457d74..388b1f67e450 100644 --- a/test/std/containers/unord/unord.multimap/reserve.pass.cpp +++ b/test/std/containers/unord/unord.multimap/reserve.pass.cpp @@ -33,6 +33,21 @@ void test(const C& c) assert(c.find(4)->second == "four"); } +void reserve_invariant(size_t n) // LWG #2156 +{ + for (size_t i = 0; i < n; ++i) + { + std::unordered_multimap<size_t, size_t> c; + c.reserve(n); + size_t buckets = c.bucket_count(); + for (size_t j = 0; j < i; ++j) + { + c.insert(std::unordered_multimap<size_t, size_t>::value_type(i,i)); + assert(buckets == c.bucket_count()); + } + } +} + int main() { { @@ -90,4 +105,5 @@ int main() test(c); } #endif + reserve_invariant(20); } diff --git a/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_noexcept.pass.cpp b/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_noexcept.pass.cpp index 37c8119060b7..7c912e01d572 100644 --- a/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_noexcept.pass.cpp +++ b/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_noexcept.pass.cpp @@ -116,7 +116,7 @@ struct some_alloc3 int main() { #if __has_feature(cxx_noexcept) - typedef std::pair<const MoveOnly, MoveOnly> MapType; + typedef std::pair<const MoveOnly, MoveOnly> V; { typedef std::unordered_multimap<MoveOnly, MoveOnly> C; C c1, c2; @@ -124,13 +124,13 @@ int main() } { typedef std::unordered_multimap<MoveOnly, MoveOnly, std::hash<MoveOnly>, - std::equal_to<MoveOnly>, test_allocator<MapType>> C; + std::equal_to<MoveOnly>, test_allocator<V>> C; C c1, c2; static_assert(noexcept(swap(c1, c2)), ""); } { typedef std::unordered_multimap<MoveOnly, MoveOnly, std::hash<MoveOnly>, - std::equal_to<MoveOnly>, other_allocator<MapType>> C; + std::equal_to<MoveOnly>, other_allocator<V>> C; C c1, c2; static_assert(noexcept(swap(c1, c2)), ""); } @@ -148,47 +148,47 @@ int main() #if TEST_STD_VER >= 14 { // POCS allocator, throwable swap for hash, throwable swap for comp - typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash<MoveOnly>, some_comp <MoveOnly>, some_alloc <MapType>> C; + typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash<MoveOnly>, some_comp <MoveOnly>, some_alloc <V>> C; C c1, c2; static_assert(!noexcept(swap(c1, c2)), ""); } { // always equal allocator, throwable swap for hash, throwable swap for comp - typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash<MoveOnly>, some_comp <MoveOnly>, some_alloc2<MapType>> C; + typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash<MoveOnly>, some_comp <MoveOnly>, some_alloc2<V>> C; C c1, c2; static_assert(!noexcept(swap(c1, c2)), ""); } { // POCS allocator, throwable swap for hash, nothrow swap for comp - typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash<MoveOnly>, some_comp2<MoveOnly>, some_alloc <MapType>> C; + typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash<MoveOnly>, some_comp2<MoveOnly>, some_alloc <V>> C; C c1, c2; static_assert(!noexcept(swap(c1, c2)), ""); } { // always equal allocator, throwable swap for hash, nothrow swap for comp - typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash<MoveOnly>, some_comp2<MoveOnly>, some_alloc2<MapType>> C; + typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash<MoveOnly>, some_comp2<MoveOnly>, some_alloc2<V>> C; C c1, c2; static_assert(!noexcept(swap(c1, c2)), ""); } { // POCS allocator, nothrow swap for hash, throwable swap for comp - typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash2<MoveOnly>, some_comp <MoveOnly>, some_alloc <MapType>> C; + typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash2<MoveOnly>, some_comp <MoveOnly>, some_alloc <V>> C; C c1, c2; static_assert(!noexcept(swap(c1, c2)), ""); } { // always equal allocator, nothrow swap for hash, throwable swap for comp - typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash2<MoveOnly>, some_comp <MoveOnly>, some_alloc2<MapType>> C; + typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash2<MoveOnly>, some_comp <MoveOnly>, some_alloc2<V>> C; C c1, c2; static_assert(!noexcept(swap(c1, c2)), ""); } { // POCS allocator, nothrow swap for hash, nothrow swap for comp - typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash2<MoveOnly>, some_comp2<MoveOnly>, some_alloc <MapType>> C; + typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash2<MoveOnly>, some_comp2<MoveOnly>, some_alloc <V>> C; C c1, c2; static_assert( noexcept(swap(c1, c2)), ""); } { // always equal allocator, nothrow swap for hash, nothrow swap for comp - typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash2<MoveOnly>, some_comp2<MoveOnly>, some_alloc2<MapType>> C; + typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash2<MoveOnly>, some_comp2<MoveOnly>, some_alloc2<V>> C; C c1, c2; static_assert( noexcept(swap(c1, c2)), ""); } { // NOT always equal allocator, nothrow swap for hash, nothrow swap for comp - typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash2<MoveOnly>, some_comp2<MoveOnly>, some_alloc3<MapType>> C; + typedef std::unordered_multimap<MoveOnly, MoveOnly, some_hash2<MoveOnly>, some_comp2<MoveOnly>, some_alloc3<V>> C; C c1, c2; static_assert( noexcept(swap(c1, c2)), ""); } diff --git a/test/std/containers/unord/unord.multiset/allocator_mismatch.fail.cpp b/test/std/containers/unord/unord.multiset/allocator_mismatch.fail.cpp new file mode 100644 index 000000000000..5836cb366159 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/allocator_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> +// The container's value type must be the same as the allocator's value type + +#include <unordered_set> + +int main() +{ + std::unordered_multiset<int, std::hash<int>, std::less<int>, std::allocator<long> > v; +} diff --git a/test/std/containers/unord/unord.multiset/rehash.pass.cpp b/test/std/containers/unord/unord.multiset/rehash.pass.cpp index bc8d461c60bf..5c7c6aa8aad3 100644 --- a/test/std/containers/unord/unord.multiset/rehash.pass.cpp +++ b/test/std/containers/unord/unord.multiset/rehash.pass.cpp @@ -21,6 +21,12 @@ #include "min_allocator.h" template <class C> +void rehash_postcondition(const C& c, size_t n) +{ + assert(c.bucket_count() >= c.size() / c.max_load_factor() && c.bucket_count() >= n); +} + +template <class C> void test(const C& c) { assert(c.size() == 6); @@ -48,13 +54,16 @@ int main() test(c); assert(c.bucket_count() >= 7); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 7); test(c); c.max_load_factor(2); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 3); test(c); c.rehash(31); + rehash_postcondition(c, 31); assert(c.bucket_count() == 31); test(c); } @@ -76,13 +85,16 @@ int main() test(c); assert(c.bucket_count() >= 7); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 7); test(c); c.max_load_factor(2); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 3); test(c); c.rehash(31); + rehash_postcondition(c, 31); assert(c.bucket_count() == 31); test(c); } diff --git a/test/std/containers/unord/unord.multiset/reserve.pass.cpp b/test/std/containers/unord/unord.multiset/reserve.pass.cpp index 0c17583d371d..1d393a09cde2 100644 --- a/test/std/containers/unord/unord.multiset/reserve.pass.cpp +++ b/test/std/containers/unord/unord.multiset/reserve.pass.cpp @@ -30,6 +30,21 @@ void test(const C& c) assert(c.count(4) == 1); } +void reserve_invariant(size_t n) // LWG #2156 +{ + for (size_t i = 0; i < n; ++i) + { + std::unordered_multiset<size_t> c; + c.reserve(n); + size_t buckets = c.bucket_count(); + for (size_t j = 0; j < i; ++j) + { + c.insert(i); + assert(buckets == c.bucket_count()); + } + } +} + int main() { { @@ -87,4 +102,5 @@ int main() test(c); } #endif + reserve_invariant(20); } diff --git a/test/std/containers/unord/unord.set/allocator_mismatch.fail.cpp b/test/std/containers/unord/unord.set/allocator_mismatch.fail.cpp new file mode 100644 index 000000000000..b87c9a24d3a5 --- /dev/null +++ b/test/std/containers/unord/unord.set/allocator_mismatch.fail.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <unordered_set> +// The container's value type must be the same as the allocator's value type + +#include <unordered_set> + +int main() +{ + std::unordered_set<int, std::hash<int>, std::less<int>, std::allocator<long> > v; +} diff --git a/test/std/containers/unord/unord.set/rehash.pass.cpp b/test/std/containers/unord/unord.set/rehash.pass.cpp index 30fffa561f78..e28c25dc8197 100644 --- a/test/std/containers/unord/unord.set/rehash.pass.cpp +++ b/test/std/containers/unord/unord.set/rehash.pass.cpp @@ -21,6 +21,12 @@ #include "min_allocator.h" template <class C> +void rehash_postcondition(const C& c, size_t n) +{ + assert(c.bucket_count() >= c.size() / c.max_load_factor() && c.bucket_count() >= n); +} + +template <class C> void test(const C& c) { assert(c.size() == 4); @@ -48,13 +54,16 @@ int main() test(c); assert(c.bucket_count() >= 5); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 5); test(c); c.max_load_factor(2); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 3); test(c); c.rehash(31); + rehash_postcondition(c, 31); assert(c.bucket_count() == 31); test(c); } @@ -76,13 +85,16 @@ int main() test(c); assert(c.bucket_count() >= 5); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 5); test(c); c.max_load_factor(2); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 3); test(c); c.rehash(31); + rehash_postcondition(c, 31); assert(c.bucket_count() == 31); test(c); } diff --git a/test/std/containers/unord/unord.set/reserve.pass.cpp b/test/std/containers/unord/unord.set/reserve.pass.cpp index 7d6656a18674..078b886b267e 100644 --- a/test/std/containers/unord/unord.set/reserve.pass.cpp +++ b/test/std/containers/unord/unord.set/reserve.pass.cpp @@ -30,6 +30,21 @@ void test(const C& c) assert(c.count(4) == 1); } +void reserve_invariant(size_t n) // LWG #2156 +{ + for (size_t i = 0; i < n; ++i) + { + std::unordered_set<size_t> c; + c.reserve(n); + size_t buckets = c.bucket_count(); + for (size_t j = 0; j < i; ++j) + { + c.insert(i); + assert(buckets == c.bucket_count()); + } + } +} + int main() { { @@ -87,4 +102,5 @@ int main() test(c); } #endif + reserve_invariant(20); } |
