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 {
};
template <typename T>
struct EnableNonNull {
struct EnableNonnull {
static_assert(nullability_internal::IsSupportedType<std::remove_cv_t<T>>,
"Template argument must be a raw or supported smart pointer "
"type. See absl/base/nullability.h.");
......@@ -86,8 +86,8 @@ using NullableImpl
#endif
= T;
template <typename T, typename = typename EnableNonNull<T>::type>
using NonNullImpl
template <typename T, typename = typename EnableNonnull<T>::type>
using NonnullImpl
#if ABSL_HAVE_CPP_ATTRIBUTE(clang::annotate)
[[clang::annotate("Nonnull")]]
#endif
......
......@@ -20,7 +20,7 @@
// expected nullability of pointers. These annotations allow you to designate
// 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.
// * "Nullable" (for pointers annotated `Nullable<T>`), indicating that it is
// valid for the given pointer to be null.
......@@ -69,7 +69,7 @@
//
// It is important to note that these annotations are not distinct strong
// *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
// the contract for the given pointer. Each annotation requires providers or
// consumers of these pointers across API boundaries to take appropriate steps
......@@ -91,13 +91,13 @@
// Example:
//
// // 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
// }
//
// // CompleteTransaction() guarantees the returned pointer to an `Account` to
// // be non-null.
// absl::NonNull<Account *> balance CompleteTransaction(double fee) {
// absl::Nonnull<Account *> balance CompleteTransaction(double fee) {
// ...
// }
//
......@@ -144,8 +144,8 @@
// These nullability annotations are primarily a human readable signal about the
// intended contract of the pointer. They are not *types* and do not currently
// provide any correctness guarantees. For example, a pointer annotated as
// `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*>`.
// `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*>`.
// ===========================================================================
#ifndef ABSL_BASE_NULLABILITY_H_
#define ABSL_BASE_NULLABILITY_H_
......@@ -154,7 +154,7 @@
namespace absl {
// absl::NonNull
// absl::Nonnull
//
// 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
......@@ -168,7 +168,7 @@ namespace absl {
// pay(*employee); // OK to dereference
// }
template <typename T>
using NonNull = nullability_internal::NonNullImpl<T>;
using Nonnull = nullability_internal::NonnullImpl<T>;
// absl::Nullable
//
......@@ -195,7 +195,7 @@ using Nullable = nullability_internal::NullableImpl<T>;
// Consumers of these pointers across an API boundary should treat such pointers
// with the same caution they treat currently unannotated pointers. Most
// 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>`.
//
// NOTE: Because this annotation is the global default state, pointers without
......
......@@ -22,73 +22,73 @@
#include "absl/base/attributes.h"
namespace {
using ::absl::NonNull;
using ::absl::Nonnull;
using ::absl::NullabilityUnknown;
using ::absl::Nullable;
void funcWithNonnullArg(NonNull<int*> /*arg*/) {}
void funcWithNonnullArg(Nonnull<int*> /*arg*/) {}
template <typename T>
void funcWithDeducedNonnullArg(NonNull<T*> /*arg*/) {}
void funcWithDeducedNonnullArg(Nonnull<T*> /*arg*/) {}
TEST(NonNullTest, NonNullArgument) {
TEST(NonnullTest, NonnullArgument) {
int var = 0;
funcWithNonnullArg(&var);
funcWithDeducedNonnullArg(&var);
}
NonNull<int*> funcWithNonnullReturn() {
Nonnull<int*> funcWithNonnullReturn() {
static int var = 0;
return &var;
}
TEST(NonNullTest, NonNullReturn) {
TEST(NonnullTest, NonnullReturn) {
auto var = funcWithNonnullReturn();
(void)var;
}
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<NullabilityUnknown<int*>, int*>::value));
}
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<NullabilityUnknown<void*>, void*>::value));
}
TEST(PassThroughTest, PassesThroughUniquePointerToInt) {
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<NullabilityUnknown<T>, T>::value));
}
TEST(PassThroughTest, PassesThroughSharedPointerToInt) {
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<NullabilityUnknown<T>, T>::value));
}
TEST(PassThroughTest, PassesThroughSharedPointerToVoid) {
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<NullabilityUnknown<T>, T>::value));
}
TEST(PassThroughTest, PassesThroughPointerToMemberObject) {
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<NullabilityUnknown<T>, T>::value));
}
TEST(PassThroughTest, PassesThroughPointerToMemberFunction) {
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<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