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 // <memory> 10 11 // template <class Alloc> 12 // struct allocator_traits 13 // { 14 // static constexpr pointer allocate(allocator_type& a, size_type n); 15 // ... 16 // }; 17 18 #include <memory> 19 #include <cstdint> 20 #include <cassert> 21 22 #include "test_macros.h" 23 #include "incomplete_type_helper.h" 24 25 template <class T> 26 struct A 27 { 28 typedef T value_type; 29 AA30 TEST_CONSTEXPR_CXX20 A() {} 31 allocateA32 TEST_CONSTEXPR_CXX20 value_type* allocate(std::size_t n) 33 { 34 assert(n == 10); 35 return &storage; 36 } 37 38 value_type storage; 39 }; 40 test()41TEST_CONSTEXPR_CXX20 bool test() 42 { 43 { 44 A<int> a; 45 assert(std::allocator_traits<A<int> >::allocate(a, 10) == &a.storage); 46 } 47 { 48 typedef A<IncompleteHolder*> Alloc; 49 Alloc a; 50 assert(std::allocator_traits<Alloc>::allocate(a, 10) == &a.storage); 51 } 52 53 return true; 54 } 55 main(int,char **)56int main(int, char**) 57 { 58 test(); 59 #if TEST_STD_VER > 17 60 static_assert(test()); 61 #endif 62 return 0; 63 } 64