overaligned.pass.cpp 957 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. // UNSUPPORTED: c++98, c++03
  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. #include "test_macros.h"
  20. struct alignas(32) A {
  21. int field;
  22. };
  23. int main(int, char**)
  24. {
  25. std::pair<A*, std::ptrdiff_t> ip = std::get_temporary_buffer<A>(5);
  26. assert(!(ip.first == nullptr) ^ (ip.second == 0));
  27. assert(reinterpret_cast<uintptr_t>(ip.first) % alignof(A) == 0);
  28. std::return_temporary_buffer(ip.first);
  29. return 0;
  30. }