allocate.pass.cpp (1200B)
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 // static pointer allocate(allocator_type& a, size_type n); 16 // ... 17 // }; 18 19 #include <memory> 20 #include <cstdint> 21 #include <cassert> 22 23 #include "incomplete_type_helper.h" 24 25 template <class T> 26 struct A 27 { 28 typedef T value_type; 29 30 value_type* allocate(std::size_t n) 31 { 32 assert(n == 10); 33 return reinterpret_cast<value_type*>(static_cast<std::uintptr_t>(0xDEADBEEF)); 34 } 35 }; 36 37 int main() 38 { 39 { 40 A<int> a; 41 assert(std::allocator_traits<A<int> >::allocate(a, 10) == reinterpret_cast<int*>(static_cast<std::uintptr_t>(0xDEADBEEF))); 42 } 43 { 44 typedef IncompleteHolder* VT; 45 typedef A<VT> Alloc; 46 Alloc a; 47 assert(std::allocator_traits<Alloc >::allocate(a, 10) == reinterpret_cast<VT*>(static_cast<std::uintptr_t>(0xDEADBEEF))); 48 } 49 }