File indexing completed on 2025-12-16 09:40:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef ABSL_BASE_INTERNAL_NULLABILITY_IMPL_H_
0016 #define ABSL_BASE_INTERNAL_NULLABILITY_IMPL_H_
0017
0018 #include <memory>
0019 #include <type_traits>
0020
0021 #include "absl/base/attributes.h"
0022 #include "absl/base/config.h"
0023 #include "absl/meta/type_traits.h"
0024
0025 namespace absl {
0026 ABSL_NAMESPACE_BEGIN
0027 namespace nullability_internal {
0028
0029
0030
0031
0032 template <typename, typename = void>
0033 struct IsNullabilityCompatible : std::false_type {};
0034
0035 template <typename T>
0036 struct IsNullabilityCompatible<
0037 T, absl::void_t<typename T::absl_nullability_compatible>> : std::true_type {
0038 };
0039
0040 template <typename T>
0041 constexpr bool IsSupportedType = IsNullabilityCompatible<T>::value;
0042
0043 template <typename T>
0044 constexpr bool IsSupportedType<T*> = true;
0045
0046 template <typename T, typename U>
0047 constexpr bool IsSupportedType<T U::*> = true;
0048
0049 template <typename T, typename... Deleter>
0050 constexpr bool IsSupportedType<std::unique_ptr<T, Deleter...>> = true;
0051
0052 template <typename T>
0053 constexpr bool IsSupportedType<std::shared_ptr<T>> = true;
0054
0055 template <typename T>
0056 struct EnableNullable {
0057 static_assert(nullability_internal::IsSupportedType<std::remove_cv_t<T>>,
0058 "Template argument must be a raw or supported smart pointer "
0059 "type. See absl/base/nullability.h.");
0060 using type = T;
0061 };
0062
0063 template <typename T>
0064 struct EnableNonnull {
0065 static_assert(nullability_internal::IsSupportedType<std::remove_cv_t<T>>,
0066 "Template argument must be a raw or supported smart pointer "
0067 "type. See absl/base/nullability.h.");
0068 using type = T;
0069 };
0070
0071 template <typename T>
0072 struct EnableNullabilityUnknown {
0073 static_assert(nullability_internal::IsSupportedType<std::remove_cv_t<T>>,
0074 "Template argument must be a raw or supported smart pointer "
0075 "type. See absl/base/nullability.h.");
0076 using type = T;
0077 };
0078
0079
0080
0081
0082
0083 template <typename T, typename = typename EnableNullable<T>::type>
0084 using NullableImpl
0085 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::annotate)
0086 [[clang::annotate("Nullable")]]
0087 #endif
0088 = T;
0089
0090 template <typename T, typename = typename EnableNonnull<T>::type>
0091 using NonnullImpl
0092 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::annotate)
0093 [[clang::annotate("Nonnull")]]
0094 #endif
0095 = T;
0096
0097 template <typename T, typename = typename EnableNullabilityUnknown<T>::type>
0098 using NullabilityUnknownImpl
0099 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::annotate)
0100 [[clang::annotate("Nullability_Unspecified")]]
0101 #endif
0102 = T;
0103
0104 }
0105 ABSL_NAMESPACE_END
0106 }
0107
0108 #endif