diff options
Diffstat (limited to 'absl/base/no_destructor.h')
-rw-r--r-- | absl/base/no_destructor.h | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/absl/base/no_destructor.h b/absl/base/no_destructor.h index ab689133..7b46456c 100644 --- a/absl/base/no_destructor.h +++ b/absl/base/no_destructor.h @@ -41,6 +41,7 @@ #include <utility> #include "absl/base/config.h" +#include "absl/base/nullability.h" namespace absl { ABSL_NAMESPACE_BEGIN @@ -140,11 +141,11 @@ class NoDestructor { // Pretend to be a smart pointer to T with deep constness. // Never returns a null pointer. T& operator*() { return *get(); } - T* operator->() { return get(); } - T* get() { return impl_.get(); } + absl::Nonnull<T*> operator->() { return get(); } + absl::Nonnull<T*> get() { return impl_.get(); } const T& operator*() const { return *get(); } - const T* operator->() const { return get(); } - const T* get() const { return impl_.get(); } + absl::Nonnull<const T*> operator->() const { return get(); } + absl::Nonnull<const T*> get() const { return impl_.get(); } private: class DirectImpl { @@ -152,8 +153,8 @@ class NoDestructor { template <typename... Args> explicit constexpr DirectImpl(Args&&... args) : value_(std::forward<Args>(args)...) {} - const T* get() const { return &value_; } - T* get() { return &value_; } + absl::Nonnull<const T*> get() const { return &value_; } + absl::Nonnull<T*> get() { return &value_; } private: T value_; @@ -165,14 +166,14 @@ class NoDestructor { explicit PlacementImpl(Args&&... args) { new (&space_) T(std::forward<Args>(args)...); } - const T* get() const { + absl::Nonnull<const T*> get() const { return Launder(reinterpret_cast<const T*>(&space_)); } - T* get() { return Launder(reinterpret_cast<T*>(&space_)); } + absl::Nonnull<T*> get() { return Launder(reinterpret_cast<T*>(&space_)); } private: template <typename P> - static P* Launder(P* p) { + static absl::Nonnull<P*> Launder(absl::Nonnull<P*> p) { #if defined(__cpp_lib_launder) && __cpp_lib_launder >= 201606L return std::launder(p); #elif ABSL_HAVE_BUILTIN(__builtin_launder) |