Commit 93ef827f by Abseil Team Committed by Copybara-Service

Rename `absl::NonNull` to `absl::Nonnull`.

The current spelling is inconsistent with standard casing rules: "nonnull" is a single word, not two.

PiperOrigin-RevId: 546034114
Change-Id: I04e5a204f4a74ebaa76031dd0b0874ca9cfa902c
parent c26cd952
...@@ -60,7 +60,7 @@ struct EnableNullable { ...@@ -60,7 +60,7 @@ struct EnableNullable {
}; };
template <typename T> template <typename T>
struct EnableNonNull { struct EnableNonnull {
static_assert(nullability_internal::IsSupportedType<std::remove_cv_t<T>>, static_assert(nullability_internal::IsSupportedType<std::remove_cv_t<T>>,
"Template argument must be a raw or supported smart pointer " "Template argument must be a raw or supported smart pointer "
"type. See absl/base/nullability.h."); "type. See absl/base/nullability.h.");
...@@ -86,8 +86,8 @@ using NullableImpl ...@@ -86,8 +86,8 @@ using NullableImpl
#endif #endif
= T; = T;
template <typename T, typename = typename EnableNonNull<T>::type> template <typename T, typename = typename EnableNonnull<T>::type>
using NonNullImpl using NonnullImpl
#if ABSL_HAVE_CPP_ATTRIBUTE(clang::annotate) #if ABSL_HAVE_CPP_ATTRIBUTE(clang::annotate)
[[clang::annotate("Nonnull")]] [[clang::annotate("Nonnull")]]
#endif #endif
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
// expected nullability of pointers. These annotations allow you to designate // expected nullability of pointers. These annotations allow you to designate
// pointers in one of three classification states: // pointers in one of three classification states:
// //
// * "Non-null" (for pointers annotated `NonNull<T>`), indicating that it is // * "Non-null" (for pointers annotated `Nonnull<T>`), indicating that it is
// invalid for the given pointer to ever be null. // invalid for the given pointer to ever be null.
// * "Nullable" (for pointers annotated `Nullable<T>`), indicating that it is // * "Nullable" (for pointers annotated `Nullable<T>`), indicating that it is
// valid for the given pointer to be null. // valid for the given pointer to be null.
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
// //
// It is important to note that these annotations are not distinct strong // It is important to note that these annotations are not distinct strong
// *types*. They are alias templates defined to be equal to the underlying // *types*. They are alias templates defined to be equal to the underlying
// pointer type. A pointer annotated `NonNull<T*>`, for example, is simply a // pointer type. A pointer annotated `Nonnull<T*>`, for example, is simply a
// pointer of type `T*`. Each annotation acts as a form of documentation about // pointer of type `T*`. Each annotation acts as a form of documentation about
// the contract for the given pointer. Each annotation requires providers or // the contract for the given pointer. Each annotation requires providers or
// consumers of these pointers across API boundaries to take appropriate steps // consumers of these pointers across API boundaries to take appropriate steps
...@@ -91,13 +91,13 @@ ...@@ -91,13 +91,13 @@
// Example: // Example:
// //
// // PaySalary() requires the passed pointer to an `Employee` to be non-null. // // PaySalary() requires the passed pointer to an `Employee` to be non-null.
// void PaySalary(absl::NonNull<Employee *> e) { // void PaySalary(absl::Nonnull<Employee *> e) {
// pay(e->salary); // OK to dereference // pay(e->salary); // OK to dereference
// } // }
// //
// // CompleteTransaction() guarantees the returned pointer to an `Account` to // // CompleteTransaction() guarantees the returned pointer to an `Account` to
// // be non-null. // // be non-null.
// absl::NonNull<Account *> balance CompleteTransaction(double fee) { // absl::Nonnull<Account *> balance CompleteTransaction(double fee) {
// ... // ...
// } // }
// //
...@@ -144,8 +144,8 @@ ...@@ -144,8 +144,8 @@
// These nullability annotations are primarily a human readable signal about the // These nullability annotations are primarily a human readable signal about the
// intended contract of the pointer. They are not *types* and do not currently // intended contract of the pointer. They are not *types* and do not currently
// provide any correctness guarantees. For example, a pointer annotated as // provide any correctness guarantees. For example, a pointer annotated as
// `NonNull<T*>` is *not guaranteed* to be non-null, and the compiler won't // `Nonnull<T*>` is *not guaranteed* to be non-null, and the compiler won't
// alert or prevent assignment of a `Nullable<T*>` to a `NonNull<T*>`. // alert or prevent assignment of a `Nullable<T*>` to a `Nonnull<T*>`.
// =========================================================================== // ===========================================================================
#ifndef ABSL_BASE_NULLABILITY_H_ #ifndef ABSL_BASE_NULLABILITY_H_
#define ABSL_BASE_NULLABILITY_H_ #define ABSL_BASE_NULLABILITY_H_
...@@ -154,7 +154,7 @@ ...@@ -154,7 +154,7 @@
namespace absl { namespace absl {
// absl::NonNull // absl::Nonnull
// //
// The indicated pointer is never null. It is the responsibility of the provider // The indicated pointer is never null. It is the responsibility of the provider
// of this pointer across an API boundary to ensure that the pointer is never be // of this pointer across an API boundary to ensure that the pointer is never be
...@@ -168,7 +168,7 @@ namespace absl { ...@@ -168,7 +168,7 @@ namespace absl {
// pay(*employee); // OK to dereference // pay(*employee); // OK to dereference
// } // }
template <typename T> template <typename T>
using NonNull = nullability_internal::NonNullImpl<T>; using Nonnull = nullability_internal::NonnullImpl<T>;
// absl::Nullable // absl::Nullable
// //
...@@ -195,7 +195,7 @@ using Nullable = nullability_internal::NullableImpl<T>; ...@@ -195,7 +195,7 @@ using Nullable = nullability_internal::NullableImpl<T>;
// Consumers of these pointers across an API boundary should treat such pointers // Consumers of these pointers across an API boundary should treat such pointers
// with the same caution they treat currently unannotated pointers. Most // with the same caution they treat currently unannotated pointers. Most
// existing code will have "unknown" pointers, which should eventually be // existing code will have "unknown" pointers, which should eventually be
// migrated into one of the above two nullability states: `NonNull<T>` or // migrated into one of the above two nullability states: `Nonnull<T>` or
// `Nullable<T>`. // `Nullable<T>`.
// //
// NOTE: Because this annotation is the global default state, pointers without // NOTE: Because this annotation is the global default state, pointers without
......
...@@ -22,73 +22,73 @@ ...@@ -22,73 +22,73 @@
#include "absl/base/attributes.h" #include "absl/base/attributes.h"
namespace { namespace {
using ::absl::NonNull; using ::absl::Nonnull;
using ::absl::NullabilityUnknown; using ::absl::NullabilityUnknown;
using ::absl::Nullable; using ::absl::Nullable;
void funcWithNonnullArg(NonNull<int*> /*arg*/) {} void funcWithNonnullArg(Nonnull<int*> /*arg*/) {}
template <typename T> template <typename T>
void funcWithDeducedNonnullArg(NonNull<T*> /*arg*/) {} void funcWithDeducedNonnullArg(Nonnull<T*> /*arg*/) {}
TEST(NonNullTest, NonNullArgument) { TEST(NonnullTest, NonnullArgument) {
int var = 0; int var = 0;
funcWithNonnullArg(&var); funcWithNonnullArg(&var);
funcWithDeducedNonnullArg(&var); funcWithDeducedNonnullArg(&var);
} }
NonNull<int*> funcWithNonnullReturn() { Nonnull<int*> funcWithNonnullReturn() {
static int var = 0; static int var = 0;
return &var; return &var;
} }
TEST(NonNullTest, NonNullReturn) { TEST(NonnullTest, NonnullReturn) {
auto var = funcWithNonnullReturn(); auto var = funcWithNonnullReturn();
(void)var; (void)var;
} }
TEST(PassThroughTest, PassesThroughRawPointerToInt) { TEST(PassThroughTest, PassesThroughRawPointerToInt) {
EXPECT_TRUE((std::is_same<NonNull<int*>, int*>::value)); EXPECT_TRUE((std::is_same<Nonnull<int*>, int*>::value));
EXPECT_TRUE((std::is_same<Nullable<int*>, int*>::value)); EXPECT_TRUE((std::is_same<Nullable<int*>, int*>::value));
EXPECT_TRUE((std::is_same<NullabilityUnknown<int*>, int*>::value)); EXPECT_TRUE((std::is_same<NullabilityUnknown<int*>, int*>::value));
} }
TEST(PassThroughTest, PassesThroughRawPointerToVoid) { TEST(PassThroughTest, PassesThroughRawPointerToVoid) {
EXPECT_TRUE((std::is_same<NonNull<void*>, void*>::value)); EXPECT_TRUE((std::is_same<Nonnull<void*>, void*>::value));
EXPECT_TRUE((std::is_same<Nullable<void*>, void*>::value)); EXPECT_TRUE((std::is_same<Nullable<void*>, void*>::value));
EXPECT_TRUE((std::is_same<NullabilityUnknown<void*>, void*>::value)); EXPECT_TRUE((std::is_same<NullabilityUnknown<void*>, void*>::value));
} }
TEST(PassThroughTest, PassesThroughUniquePointerToInt) { TEST(PassThroughTest, PassesThroughUniquePointerToInt) {
using T = std::unique_ptr<int>; using T = std::unique_ptr<int>;
EXPECT_TRUE((std::is_same<NonNull<T>, T>::value)); EXPECT_TRUE((std::is_same<Nonnull<T>, T>::value));
EXPECT_TRUE((std::is_same<Nullable<T>, T>::value)); EXPECT_TRUE((std::is_same<Nullable<T>, T>::value));
EXPECT_TRUE((std::is_same<NullabilityUnknown<T>, T>::value)); EXPECT_TRUE((std::is_same<NullabilityUnknown<T>, T>::value));
} }
TEST(PassThroughTest, PassesThroughSharedPointerToInt) { TEST(PassThroughTest, PassesThroughSharedPointerToInt) {
using T = std::shared_ptr<int>; using T = std::shared_ptr<int>;
EXPECT_TRUE((std::is_same<NonNull<T>, T>::value)); EXPECT_TRUE((std::is_same<Nonnull<T>, T>::value));
EXPECT_TRUE((std::is_same<Nullable<T>, T>::value)); EXPECT_TRUE((std::is_same<Nullable<T>, T>::value));
EXPECT_TRUE((std::is_same<NullabilityUnknown<T>, T>::value)); EXPECT_TRUE((std::is_same<NullabilityUnknown<T>, T>::value));
} }
TEST(PassThroughTest, PassesThroughSharedPointerToVoid) { TEST(PassThroughTest, PassesThroughSharedPointerToVoid) {
using T = std::shared_ptr<void>; using T = std::shared_ptr<void>;
EXPECT_TRUE((std::is_same<NonNull<T>, T>::value)); EXPECT_TRUE((std::is_same<Nonnull<T>, T>::value));
EXPECT_TRUE((std::is_same<Nullable<T>, T>::value)); EXPECT_TRUE((std::is_same<Nullable<T>, T>::value));
EXPECT_TRUE((std::is_same<NullabilityUnknown<T>, T>::value)); EXPECT_TRUE((std::is_same<NullabilityUnknown<T>, T>::value));
} }
TEST(PassThroughTest, PassesThroughPointerToMemberObject) { TEST(PassThroughTest, PassesThroughPointerToMemberObject) {
using T = decltype(&std::pair<int, int>::first); using T = decltype(&std::pair<int, int>::first);
EXPECT_TRUE((std::is_same<NonNull<T>, T>::value)); EXPECT_TRUE((std::is_same<Nonnull<T>, T>::value));
EXPECT_TRUE((std::is_same<Nullable<T>, T>::value)); EXPECT_TRUE((std::is_same<Nullable<T>, T>::value));
EXPECT_TRUE((std::is_same<NullabilityUnknown<T>, T>::value)); EXPECT_TRUE((std::is_same<NullabilityUnknown<T>, T>::value));
} }
TEST(PassThroughTest, PassesThroughPointerToMemberFunction) { TEST(PassThroughTest, PassesThroughPointerToMemberFunction) {
using T = decltype(&std::unique_ptr<int>::reset); using T = decltype(&std::unique_ptr<int>::reset);
EXPECT_TRUE((std::is_same<NonNull<T>, T>::value)); EXPECT_TRUE((std::is_same<Nonnull<T>, T>::value));
EXPECT_TRUE((std::is_same<Nullable<T>, T>::value)); EXPECT_TRUE((std::is_same<Nullable<T>, T>::value));
EXPECT_TRUE((std::is_same<NullabilityUnknown<T>, T>::value)); EXPECT_TRUE((std::is_same<NullabilityUnknown<T>, T>::value));
} }
......
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