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 // <memory> 11 12 // template <class Alloc> 13 // struct allocator_traits 14 // { 15 // template <class Ptr> 16 // static void destroy(allocator_type& a, Ptr p); 17 // ... 18 // }; 19 20 #include <memory> 21 #include <new> 22 #include <type_traits> 23 #include <cassert> 24 25 #include "test_macros.h" 26 #include "incomplete_type_helper.h" 27 28 template <class T> 29 struct A 30 { 31 typedef T value_type; 32 33 }; 34 35 int b_destroy = 0; 36 37 template <class T> 38 struct B 39 { 40 typedef T value_type; 41 42 template <class U> 43 void destroy(U* p) 44 { 45 ++b_destroy; 46 p->~U(); 47 } 48 }; 49 50 struct A0 51 { 52 static int count; 53 ~A0() {++count;} 54 }; 55 56 int A0::count = 0; 57 58 int main() 59 { 60 { 61 A0::count = 0; 62 A<int> a; 63 std::aligned_storage<sizeof(A0)>::type a0; 64 std::allocator_traits<A<int> >::construct(a, (A0*)&a0); 65 assert(A0::count == 0); 66 std::allocator_traits<A<int> >::destroy(a, (A0*)&a0); 67 assert(A0::count == 1); 68 } 69 { 70 typedef IncompleteHolder* VT; 71 typedef A<VT> Alloc; 72 Alloc a; 73 std::aligned_storage<sizeof(VT)>::type store; 74 std::allocator_traits<Alloc>::destroy(a, (VT*)&store); 75 } 76 #if TEST_STD_VER >= 11 77 { 78 A0::count = 0; 79 b_destroy = 0; 80 B<int> b; 81 std::aligned_storage<sizeof(A0)>::type a0; 82 std::allocator_traits<B<int> >::construct(b, (A0*)&a0); 83 assert(A0::count == 0); 84 assert(b_destroy == 0); 85 std::allocator_traits<B<int> >::destroy(b, (A0*)&a0); 86 assert(A0::count == 1); 87 assert(b_destroy == 1); 88 } 89 #endif 90 } 91