summaryrefslogtreecommitdiff
path: root/absl
diff options
context:
space:
mode:
authorGravatar Martin Brænne <mboehme@google.com>2024-06-17 21:38:52 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2024-06-17 21:39:57 -0700
commit69195d5bd2416a7224416887c78353ee8edf67ee (patch)
tree7a35d16bc4a3c2fc4f67d5ac4ad89de4ef632015 /absl
parentb4e4b6259ded2c394b8b6c601ab0668add4f234b (diff)
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
Diffstat (limited to 'absl')
-rw-r--r--absl/base/nullability.h29
1 files 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<T>;
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_