diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:12:08 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:12:08 +0000 |
| commit | 0564cdb94a7a1facbb0dbf888ceb90638aa70ecd (patch) | |
| tree | 3ccbf1ba827928fca93419d0b6cf83ce0f650f2a /test/std/containers/sequences/vector.bool | |
| parent | dbabdb5220c44e5938d404eefb84b5ed55667ea8 (diff) | |
Notes
Diffstat (limited to 'test/std/containers/sequences/vector.bool')
6 files changed, 149 insertions, 13 deletions
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 |
