overaligned.pass.cpp 864 B

123456789101112131415161718192021222324252627282930313233
  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. // <memory>
  10. // template <class T>
  11. // pair<T*, ptrdiff_t>
  12. // get_temporary_buffer(ptrdiff_t n);
  13. //
  14. // template <class T>
  15. // void
  16. // return_temporary_buffer(T* p);
  17. #include <memory>
  18. #include <cassert>
  19. struct alignas(32) A {
  20. int field;
  21. };
  22. int main()
  23. {
  24. std::pair<A*, std::ptrdiff_t> ip = std::get_temporary_buffer<A>(5);
  25. assert(!(ip.first == nullptr) ^ (ip.second == 0));
  26. assert(reinterpret_cast<uintptr_t>(ip.first) % alignof(A) == 0);
  27. std::return_temporary_buffer(ip.first);
  28. }