161161#include " absl/base/config.h"
162162#include " absl/base/internal/nullability_impl.h"
163163
164+ // ABSL_POINTERS_DEFAULT_NONNULL
165+ //
166+ // This macro specifies that all unannotated pointer types within the given
167+ // file are designated as nonnull (instead of the default "unknown"). This macro
168+ // exists as a standalone statement and applies default nonnull behavior to all
169+ // subsequent pointers; as a result, place this macro as the first non-comment,
170+ // non-`#include` line in a file.
171+ //
172+ // Example:
173+ //
174+ // #include "absl/base/nullability.h"
175+ //
176+ // ABSL_POINTERS_DEFAULT_NONNULL
177+ //
178+ // void FillMessage(Message *m); // implicitly non-null
179+ // absl::Nullable<T*> GetNullablePtr(); // explicitly nullable
180+ // absl::NullabilityUnknown<T*> GetUnknownPtr(); // explicitly unknown
181+ //
182+ // The macro can be safely used in header files -- it will not affect any files
183+ // that include it.
184+ //
185+ // In files with the macro, plain `T*` syntax means `absl::Nonnull<T*>`, and the
186+ // exceptions (`Nullable` and `NullabilityUnknown`) must be marked
187+ // explicitly. The same holds, correspondingly, for smart pointer types.
188+ //
189+ // For comparison, without the macro, all unannotated pointers would default to
190+ // unknown, and otherwise require explicit annotations to change this behavior:
191+ //
192+ // #include "absl/base/nullability.h"
193+ //
194+ // void FillMessage(absl::Nonnull<Message*> m); // explicitly non-null
195+ // absl::Nullable<T*> GetNullablePtr(); // explicitly nullable
196+ // T* GetUnknownPtr(); // implicitly unknown
197+ //
198+ // No-op except for being a human readable signal.
199+ #define ABSL_POINTERS_DEFAULT_NONNULL
200+
164201namespace absl {
165202ABSL_NAMESPACE_BEGIN
166203
167- // absl::Nonnull
204+ // absl::Nonnull (default with `ABSL_POINTERS_DEFAULT_NONNULL`)
168205//
169206// The indicated pointer is never null. It is the responsibility of the provider
170207// of this pointer across an API boundary to ensure that the pointer is never
@@ -197,7 +234,7 @@ using Nonnull = nullability_internal::NonnullImpl<T>;
197234template <typename T>
198235using Nullable = nullability_internal::NullableImpl<T>;
199236
200- // absl::NullabilityUnknown (default)
237+ // absl::NullabilityUnknown (default without `ABSL_POINTERS_DEFAULT_NONNULL` )
201238//
202239// The indicated pointer has not yet been determined to be definitively
203240// "non-null" or "nullable." Providers of such pointers across API boundaries
@@ -208,9 +245,10 @@ using Nullable = nullability_internal::NullableImpl<T>;
208245// migrated into one of the above two nullability states: `Nonnull<T>` or
209246// `Nullable<T>`.
210247//
211- // NOTE: Because this annotation is the global default state, unannotated
212- // pointers are assumed to have "unknown" semantics. This assumption is designed
213- // to minimize churn and reduce clutter within the codebase.
248+ // NOTE: For files that do not specify `ABSL_POINTERS_DEFAULT_NONNULL`,
249+ // because this annotation is the global default state, unannotated pointers are
250+ // are assumed to have "unknown" semantics. This assumption is designed to
251+ // minimize churn and reduce clutter within the codebase.
214252//
215253// Example:
216254//
0 commit comments