launder.pass.cpp 984 B

1234567891011121314151617181920212223242526272829303132333435
  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. // <new>
  10. // template <class T> constexpr T* launder(T* p) noexcept;
  11. // UNSUPPORTED: c++98, c++03, c++11, c++14
  12. #include <new>
  13. #include <cassert>
  14. #include "test_macros.h"
  15. constexpr int gi = 5;
  16. constexpr float gf = 8.f;
  17. int main() {
  18. static_assert(std::launder(&gi) == &gi, "" );
  19. static_assert(std::launder(&gf) == &gf, "" );
  20. const int *i = &gi;
  21. const float *f = &gf;
  22. static_assert(std::is_same<decltype(i), decltype(std::launder(i))>::value, "");
  23. static_assert(std::is_same<decltype(f), decltype(std::launder(f))>::value, "");
  24. assert(std::launder(i) == i);
  25. assert(std::launder(f) == f);
  26. }