pointer_safety.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP___MEMORY_POINTER_SAFETY_H
  10. #define _LIBCPP___MEMORY_POINTER_SAFETY_H
  11. #include <__config>
  12. #include <cstddef>
  13. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  14. #pragma GCC system_header
  15. #endif
  16. _LIBCPP_BEGIN_NAMESPACE_STD
  17. #if !defined(_LIBCPP_CXX03_LANG)
  18. enum class pointer_safety : unsigned char {
  19. relaxed,
  20. preferred,
  21. strict
  22. };
  23. inline _LIBCPP_INLINE_VISIBILITY
  24. pointer_safety get_pointer_safety() _NOEXCEPT {
  25. return pointer_safety::relaxed;
  26. }
  27. _LIBCPP_FUNC_VIS void declare_reachable(void* __p);
  28. _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
  29. _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
  30. _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
  31. template <class _Tp>
  32. inline _LIBCPP_INLINE_VISIBILITY
  33. _Tp*
  34. undeclare_reachable(_Tp* __p)
  35. {
  36. return static_cast<_Tp*>(__undeclare_reachable(__p));
  37. }
  38. #endif // !C++03
  39. _LIBCPP_END_NAMESPACE_STD
  40. #endif // _LIBCPP___MEMORY_POINTER_SAFETY_H