nonnull.h 743 B

12345678910111213141516171819202122
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_EXPLORER_COMMON_NONNULL_H_
  5. #define CARBON_EXPLORER_COMMON_NONNULL_H_
  6. #include <type_traits>
  7. namespace Carbon {
  8. // A non-nullable pointer. Written as `Nonnull<T*>` instead of `T*`.
  9. //
  10. // Sanitizers enforce this dynamically on assignment, return, and when passing
  11. // as an argument. Static analysis will also track erroneous uses of `nullptr`.
  12. template <typename T,
  13. typename std::enable_if_t<std::is_pointer_v<T>>* = nullptr>
  14. using Nonnull = T _Nonnull;
  15. } // namespace Carbon
  16. #endif // CARBON_EXPLORER_COMMON_NONNULL_H_