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 // Make sure that std::allocate_shared works with an allocator type that is 10 // only explicitly convertible from another specialization of itself. 11 12 #include <cassert> 13 #include <cstddef> 14 #include <memory> 15 16 template <class T> 17 struct ExplicitAllocator { 18 ExplicitAllocator() = default; 19 template <class U> ExplicitAllocatorExplicitAllocator20 explicit ExplicitAllocator(ExplicitAllocator<U>) { } 21 22 using value_type = T; allocateExplicitAllocator23 T* allocate(std::size_t n) { return std::allocator<T>().allocate(n); } deallocateExplicitAllocator24 void deallocate(T* ptr, std::size_t n) { return std::allocator<T>().deallocate(ptr, n); } 25 }; 26 main(int,char **)27int main(int, char**) { 28 std::shared_ptr<int> ptr = std::allocate_shared<int>(ExplicitAllocator<int>(), 0); 29 (void)ptr; 30 31 return 0; 32 } 33