Debian Codegraph @

libcxx/test/std/utilities/memory/temporary.buffer/overaligned.pass.cpp

raw
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_DISABLE_DEPRECATION_WARNINGS
12
13 // <memory>
14
15 // template <class T>
16 // pair<T*, ptrdiff_t>
17 // get_temporary_buffer(ptrdiff_t n);
18 //
19 // template <class T>
20 // void
21 // return_temporary_buffer(T* p);
22
23 #include <cassert>
24 #include <cstdint>
25 #include <memory>
26 #include <utility>
27
28 #include "test_macros.h"
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 }