nullability_impl.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2023 The Abseil Authors.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef ABSL_BASE_INTERNAL_NULLABILITY_IMPL_H_
  15. #define ABSL_BASE_INTERNAL_NULLABILITY_IMPL_H_
  16. #include <memory>
  17. #include <type_traits>
  18. #include "absl/base/attributes.h"
  19. #include "absl/base/config.h"
  20. #include "absl/meta/type_traits.h"
  21. namespace absl {
  22. ABSL_NAMESPACE_BEGIN
  23. namespace nullability_internal {
  24. template <typename T>
  25. using NullableImpl
  26. #if ABSL_HAVE_CPP_ATTRIBUTE(clang::annotate)
  27. [[clang::annotate("Nullable")]]
  28. #endif
  29. // Don't add the _Nullable attribute in Objective-C compiles. Many Objective-C
  30. // projects enable the `-Wnullable-to-nonnull-conversion warning`, which is
  31. // liable to produce false positives.
  32. #if ABSL_HAVE_FEATURE(nullability_on_classes) && !defined(__OBJC__)
  33. = T _Nullable;
  34. #else
  35. = T;
  36. #endif
  37. template <typename T>
  38. using NonnullImpl
  39. #if ABSL_HAVE_CPP_ATTRIBUTE(clang::annotate)
  40. [[clang::annotate("Nonnull")]]
  41. #endif
  42. #if ABSL_HAVE_FEATURE(nullability_on_classes) && !defined(__OBJC__)
  43. = T _Nonnull;
  44. #else
  45. = T;
  46. #endif
  47. template <typename T>
  48. using NullabilityUnknownImpl
  49. #if ABSL_HAVE_CPP_ATTRIBUTE(clang::annotate)
  50. [[clang::annotate("Nullability_Unspecified")]]
  51. #endif
  52. #if ABSL_HAVE_FEATURE(nullability_on_classes) && !defined(__OBJC__)
  53. = T _Null_unspecified;
  54. #else
  55. = T;
  56. #endif
  57. } // namespace nullability_internal
  58. ABSL_NAMESPACE_END
  59. } // namespace absl
  60. #endif // ABSL_BASE_INTERNAL_NULLABILITY_IMPL_H_