1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // vector<bool> 10 11 // vector(); 12 // vector(const Alloc&); 13 14 // This tests a conforming extension 15 // For vector<>, this was added to the standard by N4258, 16 // but vector<bool> was not changed. 17 18 19 #include <vector> 20 #include <cassert> 21 22 #include "test_macros.h" 23 #include "test_allocator.h" 24 #include "min_allocator.h" 25 26 template <class C> 27 TEST_CONSTEXPR_CXX20 void test0() 28 { 29 #if TEST_STD_VER > 14 30 LIBCPP_STATIC_ASSERT((noexcept(C{})), "" ); 31 #elif TEST_STD_VER >= 11 32 LIBCPP_STATIC_ASSERT((noexcept(C()) == noexcept(typename C::allocator_type())), "" ); 33 #endif 34 C c; 35 LIBCPP_ASSERT(c.__invariants()); 36 assert(c.empty()); 37 assert(c.get_allocator() == typename C::allocator_type()); 38 #if TEST_STD_VER >= 11 39 C c1 = {}; 40 LIBCPP_ASSERT(c1.__invariants()); 41 assert(c1.empty()); 42 assert(c1.get_allocator() == typename C::allocator_type()); 43 #endif 44 } 45 46 template <class C> 47 TEST_CONSTEXPR_CXX20 void test1(const typename C::allocator_type& a) 48 { 49 #if TEST_STD_VER > 14 50 LIBCPP_STATIC_ASSERT((noexcept(C{typename C::allocator_type{}})), "" ); 51 #elif TEST_STD_VER >= 11 52 LIBCPP_STATIC_ASSERT((noexcept(C(typename C::allocator_type())) == std::is_nothrow_copy_constructible<typename C::allocator_type>::value), "" ); 53 #endif 54 C c(a); 55 LIBCPP_ASSERT(c.__invariants()); 56 assert(c.empty()); 57 assert(c.get_allocator() == a); 58 } 59 60 TEST_CONSTEXPR_CXX20 bool tests() 61 { 62 { 63 test0<std::vector<bool> >(); 64 test1<std::vector<bool, test_allocator<bool> > >(test_allocator<bool>(3)); 65 } 66 #if TEST_STD_VER >= 11 67 { 68 test0<std::vector<bool, min_allocator<bool>> >(); 69 test1<std::vector<bool, min_allocator<bool> > >(min_allocator<bool>()); 70 } 71 { 72 test0<std::vector<bool, explicit_allocator<bool>> >(); 73 test1<std::vector<bool, explicit_allocator<bool> > >(explicit_allocator<bool>()); 74 } 75 #endif 76 77 return true; 78 } 79 80 int main(int, char**) 81 { 82 tests(); 83 #if TEST_STD_VER > 17 84 static_assert(tests()); 85 #endif 86 return 0; 87 } 88