constexpr_addressof.pass.cpp 1023 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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, c++11, c++14
  9. // XFAIL: gcc-5, gcc-6
  10. // <memory>
  11. // template <ObjectType T> constexpr T* addressof(T& r);
  12. #include <memory>
  13. #include <cassert>
  14. #include "test_macros.h"
  15. struct Pointer {
  16. constexpr Pointer(void* v) : value(v) {}
  17. void* value;
  18. };
  19. struct A
  20. {
  21. constexpr A() : n(42) {}
  22. void operator&() const { }
  23. int n;
  24. };
  25. constexpr int i = 0;
  26. constexpr double d = 0.0;
  27. constexpr A a{};
  28. int main(int, char**)
  29. {
  30. static_assert(std::addressof(i) == &i, "");
  31. static_assert(std::addressof(d) == &d, "");
  32. constexpr const A* ap = std::addressof(a);
  33. static_assert(&ap->n == &a.n, "");
  34. return 0;
  35. }