1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <vector> 11 12 // vector(const Alloc& = Alloc()); 13 14 #include <vector> 15 #include <cassert> 16 17 #include "test_allocator.h" 18 #include "../../../NotConstructible.h" 19 #include "../../../stack_allocator.h" 20 #include "min_allocator.h" 21 #include "asan_testing.h" 22 23 template <class C> 24 void test0()25test0() 26 { 27 C c; 28 assert(c.__invariants()); 29 assert(c.empty()); 30 assert(c.get_allocator() == typename C::allocator_type()); 31 assert(is_contiguous_container_asan_correct(c)); 32 #if __cplusplus >= 201103L 33 C c1 = {}; 34 assert(c1.__invariants()); 35 assert(c1.empty()); 36 assert(c1.get_allocator() == typename C::allocator_type()); 37 assert(is_contiguous_container_asan_correct(c1)); 38 #endif 39 } 40 41 template <class C> 42 void test1(const typename C::allocator_type & a)43test1(const typename C::allocator_type& a) 44 { 45 C c(a); 46 assert(c.__invariants()); 47 assert(c.empty()); 48 assert(c.get_allocator() == a); 49 assert(is_contiguous_container_asan_correct(c)); 50 } 51 main()52int main() 53 { 54 { 55 test0<std::vector<int> >(); 56 test0<std::vector<NotConstructible> >(); 57 test1<std::vector<int, test_allocator<int> > >(test_allocator<int>(3)); 58 test1<std::vector<NotConstructible, test_allocator<NotConstructible> > > 59 (test_allocator<NotConstructible>(5)); 60 } 61 { 62 std::vector<int, stack_allocator<int, 10> > v; 63 assert(v.empty()); 64 } 65 #if __cplusplus >= 201103L 66 { 67 test0<std::vector<int, min_allocator<int>> >(); 68 test0<std::vector<NotConstructible, min_allocator<NotConstructible>> >(); 69 test1<std::vector<int, min_allocator<int> > >(min_allocator<int>{}); 70 test1<std::vector<NotConstructible, min_allocator<NotConstructible> > > 71 (min_allocator<NotConstructible>{}); 72 } 73 { 74 std::vector<int, min_allocator<int> > v; 75 assert(v.empty()); 76 } 77 #endif 78 } 79