diff options
Diffstat (limited to 'test/std/containers/sequences')
35 files changed, 773 insertions, 55 deletions
diff --git a/test/std/containers/sequences/array/at.pass.cpp b/test/std/containers/sequences/array/at.pass.cpp index efec4e403001..27b326fa7ce4 100644 --- a/test/std/containers/sequences/array/at.pass.cpp +++ b/test/std/containers/sequences/array/at.pass.cpp @@ -27,7 +27,7 @@ constexpr bool check_idx( size_t idx, double val ) { std::array<double, 3> arr = {1, 2, 3.5}; - return arr.at(idx) == val; + return arr.at(idx) == val; } #endif @@ -50,7 +50,7 @@ int main() #ifndef TEST_HAS_NO_EXCEPTIONS try { - (void) c.at(3); + TEST_IGNORE_NODISCARD c.at(3); assert(false); } catch (const std::out_of_range &) {} @@ -69,7 +69,7 @@ int main() #ifndef TEST_HAS_NO_EXCEPTIONS try { - (void) c.at(3); + TEST_IGNORE_NODISCARD c.at(3); assert(false); } catch (const std::out_of_range &) {} diff --git a/test/std/containers/sequences/array/empty.fail.cpp b/test/std/containers/sequences/array/empty.fail.cpp new file mode 100644 index 000000000000..85bf5a7c9dab --- /dev/null +++ b/test/std/containers/sequences/array/empty.fail.cpp @@ -0,0 +1,28 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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> + +// class array + +// bool empty() const noexcept; + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8 + +#include <array> + +#include "test_macros.h" + +int main () +{ + std::array<int, 1> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/sequences/array/empty.pass.cpp b/test/std/containers/sequences/array/empty.pass.cpp new file mode 100644 index 000000000000..2c01dfc86c19 --- /dev/null +++ b/test/std/containers/sequences/array/empty.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class array + +// bool empty() const noexcept; + +#include <array> +#include <cassert> + +#include "test_macros.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::array<int, 2> C; + C c; + ASSERT_NOEXCEPT(c.empty()); + assert(!c.empty()); + } + { + typedef std::array<int, 0> C; + C c; + ASSERT_NOEXCEPT(c.empty()); + assert( c.empty()); + } +} diff --git a/test/std/containers/sequences/array/front_back.pass.cpp b/test/std/containers/sequences/array/front_back.pass.cpp index 68fc6cdc4543..0591ca7fac31 100644 --- a/test/std/containers/sequences/array/front_back.pass.cpp +++ b/test/std/containers/sequences/array/front_back.pass.cpp @@ -27,13 +27,13 @@ constexpr bool check_front( double val ) { std::array<double, 3> arr = {1, 2, 3.5}; - return arr.front() == val; + return arr.front() == val; } constexpr bool check_back( double val ) { std::array<double, 3> arr = {1, 2, 3.5}; - return arr.back() == val; + return arr.back() == val; } #endif diff --git a/test/std/containers/sequences/array/indexing.pass.cpp b/test/std/containers/sequences/array/indexing.pass.cpp index 3a5b9ee9727d..43c494777a9d 100644 --- a/test/std/containers/sequences/array/indexing.pass.cpp +++ b/test/std/containers/sequences/array/indexing.pass.cpp @@ -27,7 +27,7 @@ constexpr bool check_idx( size_t idx, double val ) { std::array<double, 3> arr = {1, 2, 3.5}; - return arr[idx] == val; + return arr[idx] == val; } #endif diff --git a/test/std/containers/sequences/array/max_size.pass.cpp b/test/std/containers/sequences/array/max_size.pass.cpp new file mode 100644 index 000000000000..9a3fed3950e3 --- /dev/null +++ b/test/std/containers/sequences/array/max_size.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class array + +// bool max_size() const noexcept; + +#include <array> +#include <cassert> + +#include "test_macros.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::array<int, 2> C; + C c; + ASSERT_NOEXCEPT(c.max_size()); + assert(c.max_size() == 2); + } + { + typedef std::array<int, 0> C; + C c; + ASSERT_NOEXCEPT(c.max_size()); + assert(c.max_size() == 0); + } +} diff --git a/test/std/containers/sequences/deque/deque.capacity/empty.fail.cpp b/test/std/containers/sequences/deque/deque.capacity/empty.fail.cpp new file mode 100644 index 000000000000..adfd5f2d8167 --- /dev/null +++ b/test/std/containers/sequences/deque/deque.capacity/empty.fail.cpp @@ -0,0 +1,28 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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> + +// class deque + +// bool empty() const noexcept; + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8 + +#include <deque> + +#include "test_macros.h" + +int main () +{ + std::deque<int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/sequences/deque/deque.capacity/empty.pass.cpp b/test/std/containers/sequences/deque/deque.capacity/empty.pass.cpp new file mode 100644 index 000000000000..629a51cab95b --- /dev/null +++ b/test/std/containers/sequences/deque/deque.capacity/empty.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class deque + +// bool empty() const noexcept; + +#include <deque> +#include <cassert> + +#include "test_macros.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::deque<int> C; + C c; + ASSERT_NOEXCEPT(c.empty()); + assert(c.empty()); + c.push_back(C::value_type(1)); + assert(!c.empty()); + c.clear(); + assert(c.empty()); + } +#if TEST_STD_VER >= 11 + { + typedef std::deque<int, min_allocator<int>> C; + C c; + ASSERT_NOEXCEPT(c.empty()); + assert(c.empty()); + c.push_back(C::value_type(1)); + assert(!c.empty()); + c.clear(); + assert(c.empty()); + } +#endif +} diff --git a/test/std/containers/sequences/deque/deque.capacity/size.pass.cpp b/test/std/containers/sequences/deque/deque.capacity/size.pass.cpp new file mode 100644 index 000000000000..4974fc74d0b1 --- /dev/null +++ b/test/std/containers/sequences/deque/deque.capacity/size.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class deque + +// size_type size() const noexcept; + +#include <deque> +#include <cassert> + +#include "test_macros.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::deque<int> C; + C c; + ASSERT_NOEXCEPT(c.size()); + assert(c.size() == 0); + c.push_back(C::value_type(2)); + assert(c.size() == 1); + c.push_back(C::value_type(1)); + assert(c.size() == 2); + c.push_back(C::value_type(3)); + assert(c.size() == 3); + c.erase(c.begin()); + assert(c.size() == 2); + c.erase(c.begin()); + assert(c.size() == 1); + c.erase(c.begin()); + assert(c.size() == 0); + } +#if TEST_STD_VER >= 11 + { + typedef std::deque<int, min_allocator<int>> C; + C c; + ASSERT_NOEXCEPT(c.size()); + assert(c.size() == 0); + c.push_back(C::value_type(2)); + assert(c.size() == 1); + c.push_back(C::value_type(1)); + assert(c.size() == 2); + c.push_back(C::value_type(3)); + assert(c.size() == 3); + c.erase(c.begin()); + assert(c.size() == 2); + c.erase(c.begin()); + assert(c.size() == 1); + c.erase(c.begin()); + assert(c.size() == 0); + } +#endif +} diff --git a/test/std/containers/sequences/deque/deque.cons/move_noexcept.pass.cpp b/test/std/containers/sequences/deque/deque.cons/move_noexcept.pass.cpp index fdf67d23a12d..baae755bc27d 100644 --- a/test/std/containers/sequences/deque/deque.cons/move_noexcept.pass.cpp +++ b/test/std/containers/sequences/deque/deque.cons/move_noexcept.pass.cpp @@ -45,9 +45,9 @@ int main() typedef std::deque<MoveOnly, other_allocator<MoveOnly>> C; static_assert(std::is_nothrow_move_constructible<C>::value, ""); } -#endif // _LIBCPP_VERSION { typedef std::deque<MoveOnly, some_alloc<MoveOnly>> C; static_assert(!std::is_nothrow_move_constructible<C>::value, ""); } +#endif // _LIBCPP_VERSION } 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 db22086fd4c9..4c1e15f7acb8 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 @@ -80,17 +80,17 @@ int main() assert(false); } catch (...) { - gCopyConstructorShouldThow = false; + gCopyConstructorShouldThow = false; assert(vec==vec2); } - } + } - { - typedef std::deque<CMyClass, test_allocator<CMyClass> > C; + { + typedef std::deque<CMyClass, test_allocator<CMyClass> > C; C vec; C vec2(vec); - C::allocator_type::throw_after = 1; + C::allocator_type::throw_after = 1; try { vec.push_back(instance); assert(false); 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 7a90c8a75962..0688ed025089 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 @@ -80,17 +80,17 @@ int main() assert(false); } catch (...) { - gCopyConstructorShouldThow = false; + gCopyConstructorShouldThow = false; assert(vec==vec2); } - } + } - { - typedef std::deque<CMyClass, test_allocator<CMyClass> > C; + { + typedef std::deque<CMyClass, test_allocator<CMyClass> > C; C vec; C vec2(vec); - C::allocator_type::throw_after = 1; + C::allocator_type::throw_after = 1; try { vec.push_front(instance); assert(false); diff --git a/test/std/containers/sequences/deque/deque.special/swap_noexcept.pass.cpp b/test/std/containers/sequences/deque/deque.special/swap_noexcept.pass.cpp index 0db30a031282..01a10964b77f 100644 --- a/test/std/containers/sequences/deque/deque.special/swap_noexcept.pass.cpp +++ b/test/std/containers/sequences/deque/deque.special/swap_noexcept.pass.cpp @@ -72,7 +72,7 @@ int main() { typedef std::deque<MoveOnly, some_alloc<MoveOnly>> C; #if TEST_STD_VER >= 14 - // In c++14, if POCS is set, swapping the allocator is required not to throw + // In C++14, if POCS is set, swapping the allocator is required not to throw static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), ""); #else static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), ""); diff --git a/test/std/containers/sequences/forwardlist/empty.fail.cpp b/test/std/containers/sequences/forwardlist/empty.fail.cpp new file mode 100644 index 000000000000..78928b480c9a --- /dev/null +++ b/test/std/containers/sequences/forwardlist/empty.fail.cpp @@ -0,0 +1,28 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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> + +// class forward_list + +// bool empty() const noexcept; + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8 + +#include <forward_list> + +#include "test_macros.h" + +int main () +{ + std::forward_list<int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/sequences/forwardlist/empty.pass.cpp b/test/std/containers/sequences/forwardlist/empty.pass.cpp new file mode 100644 index 000000000000..1226e68ed3c8 --- /dev/null +++ b/test/std/containers/sequences/forwardlist/empty.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class forward_list + +// bool empty() const noexcept; + +#include <forward_list> +#include <cassert> + +#include "test_macros.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::forward_list<int> C; + C c; + ASSERT_NOEXCEPT(c.empty()); + assert(c.empty()); + c.push_front(C::value_type(1)); + assert(!c.empty()); + c.clear(); + assert(c.empty()); + } +#if TEST_STD_VER >= 11 + { + typedef std::forward_list<int, min_allocator<int>> C; + C c; + ASSERT_NOEXCEPT(c.empty()); + assert(c.empty()); + c.push_front(C::value_type(1)); + assert(!c.empty()); + c.clear(); + assert(c.empty()); + } +#endif +} diff --git a/test/std/containers/sequences/forwardlist/forwardlist.cons/move_noexcept.pass.cpp b/test/std/containers/sequences/forwardlist/forwardlist.cons/move_noexcept.pass.cpp index 3390c331e00e..a4c776abc3e5 100644 --- a/test/std/containers/sequences/forwardlist/forwardlist.cons/move_noexcept.pass.cpp +++ b/test/std/containers/sequences/forwardlist/forwardlist.cons/move_noexcept.pass.cpp @@ -45,9 +45,9 @@ int main() typedef std::forward_list<MoveOnly, other_allocator<MoveOnly>> C; static_assert(std::is_nothrow_move_constructible<C>::value, ""); } -#endif // _LIBCPP_VERSION { typedef std::forward_list<MoveOnly, some_alloc<MoveOnly>> C; static_assert(!std::is_nothrow_move_constructible<C>::value, ""); } +#endif // _LIBCPP_VERSION } diff --git a/test/std/containers/sequences/forwardlist/forwardlist.spec/swap_noexcept.pass.cpp b/test/std/containers/sequences/forwardlist/forwardlist.spec/swap_noexcept.pass.cpp index d93c079e15ed..ae48d1a4b95c 100644 --- a/test/std/containers/sequences/forwardlist/forwardlist.spec/swap_noexcept.pass.cpp +++ b/test/std/containers/sequences/forwardlist/forwardlist.spec/swap_noexcept.pass.cpp @@ -72,7 +72,7 @@ int main() { typedef std::forward_list<MoveOnly, some_alloc<MoveOnly>> C; #if TEST_STD_VER >= 14 - // In c++14, if POCS is set, swapping the allocator is required not to throw + // In C++14, if POCS is set, swapping the allocator is required not to throw static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), ""); #else static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), ""); diff --git a/test/std/containers/sequences/list/list.capacity/empty.fail.cpp b/test/std/containers/sequences/list/list.capacity/empty.fail.cpp new file mode 100644 index 000000000000..fe0387c834d4 --- /dev/null +++ b/test/std/containers/sequences/list/list.capacity/empty.fail.cpp @@ -0,0 +1,28 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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> + +// class list + +// bool empty() const noexcept; + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8 + +#include <list> + +#include "test_macros.h" + +int main () +{ + std::list<int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/sequences/list/list.capacity/empty.pass.cpp b/test/std/containers/sequences/list/list.capacity/empty.pass.cpp new file mode 100644 index 000000000000..b564990f2d0c --- /dev/null +++ b/test/std/containers/sequences/list/list.capacity/empty.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class list + +// bool empty() const noexcept; + +#include <list> +#include <cassert> + +#include "test_macros.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::list<int> C; + C c; + ASSERT_NOEXCEPT(c.empty()); + assert(c.empty()); + c.push_back(C::value_type(1)); + assert(!c.empty()); + c.clear(); + assert(c.empty()); + } +#if TEST_STD_VER >= 11 + { + typedef std::list<int, min_allocator<int>> C; + C c; + ASSERT_NOEXCEPT(c.empty()); + assert(c.empty()); + c.push_back(C::value_type(1)); + assert(!c.empty()); + c.clear(); + assert(c.empty()); + } +#endif +} diff --git a/test/std/containers/sequences/list/list.capacity/size.pass.cpp b/test/std/containers/sequences/list/list.capacity/size.pass.cpp new file mode 100644 index 000000000000..bddaeb5ac04d --- /dev/null +++ b/test/std/containers/sequences/list/list.capacity/size.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class list + +// size_type size() const noexcept; + +#include <list> +#include <cassert> + +#include "test_macros.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::list<int> C; + C c; + ASSERT_NOEXCEPT(c.size()); + assert(c.size() == 0); + c.push_back(C::value_type(2)); + assert(c.size() == 1); + c.push_back(C::value_type(1)); + assert(c.size() == 2); + c.push_back(C::value_type(3)); + assert(c.size() == 3); + c.erase(c.begin()); + assert(c.size() == 2); + c.erase(c.begin()); + assert(c.size() == 1); + c.erase(c.begin()); + assert(c.size() == 0); + } +#if TEST_STD_VER >= 11 + { + typedef std::list<int, min_allocator<int>> C; + C c; + ASSERT_NOEXCEPT(c.size()); + assert(c.size() == 0); + c.push_back(C::value_type(2)); + assert(c.size() == 1); + c.push_back(C::value_type(1)); + assert(c.size() == 2); + c.push_back(C::value_type(3)); + assert(c.size() == 3); + c.erase(c.begin()); + assert(c.size() == 2); + c.erase(c.begin()); + assert(c.size() == 1); + c.erase(c.begin()); + assert(c.size() == 0); + } +#endif +} diff --git a/test/std/containers/sequences/list/list.special/swap_noexcept.pass.cpp b/test/std/containers/sequences/list/list.special/swap_noexcept.pass.cpp index cfe1bfd2f411..acb68f3b5beb 100644 --- a/test/std/containers/sequences/list/list.special/swap_noexcept.pass.cpp +++ b/test/std/containers/sequences/list/list.special/swap_noexcept.pass.cpp @@ -72,7 +72,7 @@ int main() { typedef std::list<MoveOnly, some_alloc<MoveOnly>> C; #if TEST_STD_VER >= 14 - // In c++14, if POCS is set, swapping the allocator is required not to throw + // In C++14, if POCS is set, swapping the allocator is required not to throw static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), ""); #else static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), ""); diff --git a/test/std/containers/sequences/list/types.pass.cpp b/test/std/containers/sequences/list/types.pass.cpp index 7d5f5b6fa2f0..8c47606fadcc 100644 --- a/test/std/containers/sequences/list/types.pass.cpp +++ b/test/std/containers/sequences/list/types.pass.cpp @@ -31,8 +31,8 @@ struct A { std::list<A> v; }; // incomplete type support int main() { - { - typedef std::list<int> C; + { + typedef std::list<int> C; static_assert((std::is_same<C::value_type, int>::value), ""); static_assert((std::is_same<C::allocator_type, std::allocator<int> >::value), ""); static_assert((std::is_same<C::reference, std::allocator<int>::reference>::value), ""); @@ -46,11 +46,11 @@ int main() typename std::iterator_traits<typename C::iterator>::difference_type>::value), ""); static_assert((std::is_same<typename C::difference_type, typename std::iterator_traits<typename C::const_iterator>::difference_type>::value), ""); - } + } #if TEST_STD_VER >= 11 { - typedef std::list<int, min_allocator<int>> C; + typedef std::list<int, min_allocator<int>> C; static_assert((std::is_same<C::value_type, int>::value), ""); static_assert((std::is_same<C::allocator_type, min_allocator<int> >::value), ""); static_assert((std::is_same<C::reference, int&>::value), ""); diff --git a/test/std/containers/sequences/vector.bool/construct_default.pass.cpp b/test/std/containers/sequences/vector.bool/construct_default.pass.cpp index a18ba8fbaab7..0f51c219ee49 100644 --- a/test/std/containers/sequences/vector.bool/construct_default.pass.cpp +++ b/test/std/containers/sequences/vector.bool/construct_default.pass.cpp @@ -24,9 +24,9 @@ void test0() { #if TEST_STD_VER > 14 - static_assert((noexcept(C{})), "" ); + static_assert((noexcept(C{})), "" ); #elif TEST_STD_VER >= 11 - static_assert((noexcept(C()) == noexcept(typename C::allocator_type())), "" ); + static_assert((noexcept(C()) == noexcept(typename C::allocator_type())), "" ); #endif C c; LIBCPP_ASSERT(c.__invariants()); @@ -45,9 +45,9 @@ void test1(const typename C::allocator_type& a) { #if TEST_STD_VER > 14 - static_assert((noexcept(C{typename C::allocator_type{}})), "" ); + static_assert((noexcept(C{typename C::allocator_type{}})), "" ); #elif TEST_STD_VER >= 11 - static_assert((noexcept(C(typename C::allocator_type())) == std::is_nothrow_copy_constructible<typename C::allocator_type>::value), "" ); + static_assert((noexcept(C(typename C::allocator_type())) == std::is_nothrow_copy_constructible<typename C::allocator_type>::value), "" ); #endif C c(a); LIBCPP_ASSERT(c.__invariants()); diff --git a/test/std/containers/sequences/vector.bool/empty.fail.cpp b/test/std/containers/sequences/vector.bool/empty.fail.cpp new file mode 100644 index 000000000000..99c245d0c09c --- /dev/null +++ b/test/std/containers/sequences/vector.bool/empty.fail.cpp @@ -0,0 +1,28 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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> + +// class vector + +// bool empty() const noexcept; + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8 + +#include <vector> + +#include "test_macros.h" + +int main () +{ + std::vector<bool> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/sequences/vector.bool/empty.pass.cpp b/test/std/containers/sequences/vector.bool/empty.pass.cpp new file mode 100644 index 000000000000..1471c39ebb07 --- /dev/null +++ b/test/std/containers/sequences/vector.bool/empty.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class vector + +// bool empty() const noexcept; + +#include <vector> +#include <cassert> + +#include "test_macros.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::vector<bool> C; + C c; + ASSERT_NOEXCEPT(c.empty()); + assert(c.empty()); + c.push_back(false); + assert(!c.empty()); + c.clear(); + assert(c.empty()); + } +#if TEST_STD_VER >= 11 + { + typedef std::vector<bool, min_allocator<bool>> C; + C c; + ASSERT_NOEXCEPT(c.empty()); + assert(c.empty()); + c.push_back(false); + assert(!c.empty()); + c.clear(); + assert(c.empty()); + } +#endif +} diff --git a/test/std/containers/sequences/vector.bool/reference.swap.pass.cpp b/test/std/containers/sequences/vector.bool/reference.swap.pass.cpp index 06351e418ac4..8fe18d4b4f84 100644 --- a/test/std/containers/sequences/vector.bool/reference.swap.pass.cpp +++ b/test/std/containers/sequences/vector.bool/reference.swap.pass.cpp @@ -23,17 +23,17 @@ int main() bool a[] = {false, true, false, true}; bool* an = a + sizeof(a)/sizeof(a[0]); - std::vector<bool> v(a, an); - std::vector<bool>::reference r1 = v[0]; - std::vector<bool>::reference r2 = v[3]; + std::vector<bool> v(a, an); + std::vector<bool>::reference r1 = v[0]; + std::vector<bool>::reference r2 = v[3]; #if TEST_STD_VER >= 11 static_assert((noexcept(v.swap(r1,r2))), ""); #endif - assert(!r1); - assert( r2); - v.swap(r1, r2); - assert( r1); - assert(!r2); + assert(!r1); + assert( r2); + v.swap(r1, r2); + assert( r1); + assert(!r2); } diff --git a/test/std/containers/sequences/vector.bool/size.pass.cpp b/test/std/containers/sequences/vector.bool/size.pass.cpp new file mode 100644 index 000000000000..43330c0a5224 --- /dev/null +++ b/test/std/containers/sequences/vector.bool/size.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class vector + +// size_type size() const noexcept; + +#include <vector> +#include <cassert> + +#include "test_macros.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::vector<bool> C; + C c; + ASSERT_NOEXCEPT(c.size()); + assert(c.size() == 0); + c.push_back(false); + assert(c.size() == 1); + c.push_back(true); + assert(c.size() == 2); + c.push_back(false); + assert(c.size() == 3); + c.erase(c.begin()); + assert(c.size() == 2); + c.erase(c.begin()); + assert(c.size() == 1); + c.erase(c.begin()); + assert(c.size() == 0); + } +#if TEST_STD_VER >= 11 + { + typedef std::vector<bool, min_allocator<bool>> C; + C c; + ASSERT_NOEXCEPT(c.size()); + assert(c.size() == 0); + c.push_back(false); + assert(c.size() == 1); + c.push_back(true); + assert(c.size() == 2); + c.push_back(false); + assert(c.size() == 3); + c.erase(c.begin()); + assert(c.size() == 2); + c.erase(c.begin()); + assert(c.size() == 1); + c.erase(c.begin()); + assert(c.size() == 0); + } +#endif +} diff --git a/test/std/containers/sequences/vector.bool/swap_noexcept.pass.cpp b/test/std/containers/sequences/vector.bool/swap_noexcept.pass.cpp index d888af05f92f..68d04dbb3e9f 100644 --- a/test/std/containers/sequences/vector.bool/swap_noexcept.pass.cpp +++ b/test/std/containers/sequences/vector.bool/swap_noexcept.pass.cpp @@ -72,7 +72,7 @@ int main() { #if TEST_STD_VER >= 14 #if defined(_LIBCPP_VERSION) - // In c++14, if POCS is set, swapping the allocator is required not to throw + // In C++14, if POCS is set, swapping the allocator is required not to throw typedef std::vector<bool, some_alloc<bool>> C; static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), ""); #endif // _LIBCPP_VERSION diff --git a/test/std/containers/sequences/vector/vector.capacity/empty.fail.cpp b/test/std/containers/sequences/vector/vector.capacity/empty.fail.cpp new file mode 100644 index 000000000000..abfdfbfb9c42 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.capacity/empty.fail.cpp @@ -0,0 +1,28 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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> + +// class vector + +// bool empty() const noexcept; + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8 + +#include <vector> + +#include "test_macros.h" + +int main () +{ + std::vector<int> c; + c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/containers/sequences/vector/vector.capacity/empty.pass.cpp b/test/std/containers/sequences/vector/vector.capacity/empty.pass.cpp new file mode 100644 index 000000000000..d81683133f5c --- /dev/null +++ b/test/std/containers/sequences/vector/vector.capacity/empty.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class vector + +// bool empty() const noexcept; + +#include <vector> +#include <cassert> + +#include "test_macros.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::vector<int> C; + C c; + ASSERT_NOEXCEPT(c.empty()); + assert(c.empty()); + c.push_back(C::value_type(1)); + assert(!c.empty()); + c.clear(); + assert(c.empty()); + } +#if TEST_STD_VER >= 11 + { + typedef std::vector<int, min_allocator<int>> C; + C c; + ASSERT_NOEXCEPT(c.empty()); + assert(c.empty()); + c.push_back(C::value_type(1)); + assert(!c.empty()); + c.clear(); + assert(c.empty()); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.capacity/size.pass.cpp b/test/std/containers/sequences/vector/vector.capacity/size.pass.cpp new file mode 100644 index 000000000000..71f531c48888 --- /dev/null +++ b/test/std/containers/sequences/vector/vector.capacity/size.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class vector + +// size_type size() const noexcept; + +#include <vector> +#include <cassert> + +#include "test_macros.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::vector<int> C; + C c; + ASSERT_NOEXCEPT(c.size()); + assert(c.size() == 0); + c.push_back(C::value_type(2)); + assert(c.size() == 1); + c.push_back(C::value_type(1)); + assert(c.size() == 2); + c.push_back(C::value_type(3)); + assert(c.size() == 3); + c.erase(c.begin()); + assert(c.size() == 2); + c.erase(c.begin()); + assert(c.size() == 1); + c.erase(c.begin()); + assert(c.size() == 0); + } +#if TEST_STD_VER >= 11 + { + typedef std::vector<int, min_allocator<int>> C; + C c; + ASSERT_NOEXCEPT(c.size()); + assert(c.size() == 0); + c.push_back(C::value_type(2)); + assert(c.size() == 1); + c.push_back(C::value_type(1)); + assert(c.size() == 2); + c.push_back(C::value_type(3)); + assert(c.size() == 3); + c.erase(c.begin()); + assert(c.size() == 2); + c.erase(c.begin()); + assert(c.size() == 1); + c.erase(c.begin()); + assert(c.size() == 0); + } +#endif +} diff --git a/test/std/containers/sequences/vector/vector.cons/construct_default.pass.cpp b/test/std/containers/sequences/vector/vector.cons/construct_default.pass.cpp index edeae04d7bd7..a71f5b32c039 100644 --- a/test/std/containers/sequences/vector/vector.cons/construct_default.pass.cpp +++ b/test/std/containers/sequences/vector/vector.cons/construct_default.pass.cpp @@ -27,9 +27,9 @@ void test0() { #if TEST_STD_VER > 14 - static_assert((noexcept(C{})), "" ); + static_assert((noexcept(C{})), "" ); #elif TEST_STD_VER >= 11 - static_assert((noexcept(C()) == noexcept(typename C::allocator_type())), "" ); + static_assert((noexcept(C()) == noexcept(typename C::allocator_type())), "" ); #endif C c; LIBCPP_ASSERT(c.__invariants()); @@ -50,9 +50,9 @@ void test1(const typename C::allocator_type& a) { #if TEST_STD_VER > 14 - static_assert((noexcept(C{typename C::allocator_type{}})), "" ); + static_assert((noexcept(C{typename C::allocator_type{}})), "" ); #elif TEST_STD_VER >= 11 - static_assert((noexcept(C(typename C::allocator_type())) == std::is_nothrow_copy_constructible<typename C::allocator_type>::value), "" ); + static_assert((noexcept(C(typename C::allocator_type())) == std::is_nothrow_copy_constructible<typename C::allocator_type>::value), "" ); #endif C c(a); LIBCPP_ASSERT(c.__invariants()); diff --git a/test/std/containers/sequences/vector/vector.data/data.pass.cpp b/test/std/containers/sequences/vector/vector.data/data.pass.cpp index b7ea3a286f32..0fc335f15ac9 100644 --- a/test/std/containers/sequences/vector/vector.data/data.pass.cpp +++ b/test/std/containers/sequences/vector/vector.data/data.pass.cpp @@ -18,13 +18,13 @@ #include "asan_testing.h" struct Nasty { - Nasty() : i_(0) {} - Nasty(int i) : i_(i) {} - ~Nasty() {} + Nasty() : i_(0) {} + Nasty(int i) : i_(i) {} + ~Nasty() {} - Nasty * operator&() const { assert(false); return nullptr; } - int i_; - }; + Nasty * operator&() const { assert(false); return nullptr; } + int i_; + }; int main() { diff --git a/test/std/containers/sequences/vector/vector.data/data_const.pass.cpp b/test/std/containers/sequences/vector/vector.data/data_const.pass.cpp index 3c013c1ae8af..fa8b6a8afdf2 100644 --- a/test/std/containers/sequences/vector/vector.data/data_const.pass.cpp +++ b/test/std/containers/sequences/vector/vector.data/data_const.pass.cpp @@ -18,13 +18,13 @@ #include "asan_testing.h" struct Nasty { - Nasty() : i_(0) {} - Nasty(int i) : i_(i) {} - ~Nasty() {} + Nasty() : i_(0) {} + Nasty(int i) : i_(i) {} + ~Nasty() {} - Nasty * operator&() const { assert(false); return nullptr; } - int i_; - }; + Nasty * operator&() const { assert(false); return nullptr; } + int i_; + }; int main() { diff --git a/test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp b/test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp index f92ab8a5c300..062ee22c3fd9 100644 --- a/test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp +++ b/test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp @@ -73,7 +73,7 @@ int main() { typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C; #if TEST_STD_VER >= 14 - // In c++14, if POCS is set, swapping the allocator is required not to throw + // In C++14, if POCS is set, swapping the allocator is required not to throw static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), ""); #else static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), ""); |