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 // UNSUPPORTED: c++03 10 11 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER 12 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS 13 14 // <memory> 15 16 // template <class T> 17 // pair<T*, ptrdiff_t> 18 // get_temporary_buffer(ptrdiff_t n); 19 // 20 // template <class T> 21 // void 22 // return_temporary_buffer(T* p); 23 24 #include <cassert> 25 #include <cstddef> 26 #include <cstdint> 27 #include <memory> 28 #include <utility> 29 30 struct alignas(32) A { 31 int field; 32 }; 33 34 int main(int, char**) 35 { 36 std::pair<A*, std::ptrdiff_t> ip = std::get_temporary_buffer<A>(5); 37 assert(!(ip.first == nullptr) ^ (ip.second == 0)); 38 assert(reinterpret_cast<std::uintptr_t>(ip.first) % alignof(A) == 0); 39 std::return_temporary_buffer(ip.first); 40 41 return 0; 42 } 43