From 69195d5bd2416a7224416887c78353ee8edf67ee Mon Sep 17 00:00:00 2001 From: Martin Brænne Date: Mon, 17 Jun 2024 21:38:52 -0700 Subject: Add `ABSL_NULLABILITY_COMPATIBLE` attribute. This is a replacement for the `absl_nullability_compatible` tag. The attribute has the advantage that, unlike the tag, it can be applied to forward declarations. This does not yet change the implementation of the nullability annotations -- that will come in a followup patch. As the nullability annotations themselves have not been changed, the `absl_nullability_compatible` tag is currently still used to check whether the annotations can be applied to a given type; see also the comments in the code. PiperOrigin-RevId: 644238698 Change-Id: I5882606f82ce7a6dd98e83e6d920573437561b50 --- absl/base/nullability.h | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/absl/base/nullability.h b/absl/base/nullability.h index 7804de2e..077bd42f 100644 --- a/absl/base/nullability.h +++ b/absl/base/nullability.h @@ -128,9 +128,17 @@ // // By default, nullability annotations are applicable to raw and smart // pointers. User-defined types can indicate compatibility with nullability -// annotations by providing an `absl_nullability_compatible` nested type. The -// actual definition of this inner type is not relevant as it is used merely as -// a marker. It is common to use a using declaration of +// annotations by adding the ABSL_NULLABILITY_COMPATIBLE attribute. +// +// // Example: +// struct ABSL_NULLABILITY_COMPATIBLE MyPtr { +// ... +// }; +// +// Note: For the time being, nullability-compatible classes should additionally +// be marked with an `absl_nullability_compatible` nested type (this will soon +// be deprecated). The actual definition of this inner type is not relevant as +// it is used merely as a marker. It is common to use a using declaration of // `absl_nullability_compatible` set to void. // // // Example: @@ -224,4 +232,19 @@ using NullabilityUnknown = nullability_internal::NullabilityUnknownImpl; ABSL_NAMESPACE_END } // namespace absl +// ABSL_NULLABILITY_COMPATIBLE +// +// Indicates that a class is compatible with nullability annotations. +// +// For example: +// +// struct ABSL_NULLABILITY_COMPATIBLE MyPtr { +// ... +// }; +#if ABSL_HAVE_FEATURE(nullability_on_classes) +#define ABSL_NULLABILITY_COMPATIBLE _Nullable +#else +#define ABSL_NULLABILITY_COMPATIBLE +#endif + #endif // ABSL_BASE_NULLABILITY_H_ -- cgit v1.2.3