Commit 69195d5b by Martin Brænne Committed by Copybara-Service

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
parent b4e4b625
...@@ -128,9 +128,17 @@ ...@@ -128,9 +128,17 @@
// //
// By default, nullability annotations are applicable to raw and smart // By default, nullability annotations are applicable to raw and smart
// pointers. User-defined types can indicate compatibility with nullability // pointers. User-defined types can indicate compatibility with nullability
// annotations by providing an `absl_nullability_compatible` nested type. The // annotations by adding the ABSL_NULLABILITY_COMPATIBLE attribute.
// 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 // // 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. // `absl_nullability_compatible` set to void.
// //
// // Example: // // Example:
...@@ -224,4 +232,19 @@ using NullabilityUnknown = nullability_internal::NullabilityUnknownImpl<T>; ...@@ -224,4 +232,19 @@ using NullabilityUnknown = nullability_internal::NullabilityUnknownImpl<T>;
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // 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_ #endif // ABSL_BASE_NULLABILITY_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment