address.pass.cpp 887 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. // <memory>
  9. // allocator:
  10. // pointer address(reference x) const;
  11. // const_pointer address(const_reference x) const;
  12. #include <memory>
  13. #include <cassert>
  14. #include "test_macros.h"
  15. template <class T>
  16. void test_address()
  17. {
  18. T* tp = new T();
  19. const T* ctp = tp;
  20. const std::allocator<T> a;
  21. assert(a.address(*tp) == tp);
  22. assert(a.address(*ctp) == tp);
  23. delete tp;
  24. }
  25. struct A
  26. {
  27. void operator&() const {}
  28. };
  29. int main(int, char**)
  30. {
  31. test_address<int>();
  32. test_address<A>();
  33. return 0;
  34. }