diff options
-rw-r--r-- | absl/functional/any_invocable.h | 9 | ||||
-rw-r--r-- | absl/functional/internal/any_invocable.h | 2 |
2 files changed, 10 insertions, 1 deletions
diff --git a/absl/functional/any_invocable.h b/absl/functional/any_invocable.h index 176077ae..bc980731 100644 --- a/absl/functional/any_invocable.h +++ b/absl/functional/any_invocable.h @@ -151,6 +151,12 @@ ABSL_NAMESPACE_BEGIN // // Attempting to call `absl::AnyInvocable` multiple times in such a case // results in undefined behavior. +// +// Invoking an empty `absl::AnyInvocable` results in undefined behavior: +// +// // Create an empty instance using the default constructor. +// AnyInvocable<void()> empty; +// empty(); // WARNING: Undefined behavior! template <class Sig> class AnyInvocable : private internal_any_invocable::Impl<Sig> { private: @@ -167,6 +173,7 @@ class AnyInvocable : private internal_any_invocable::Impl<Sig> { // Constructors // Constructs the `AnyInvocable` in an empty state. + // Invoking it results in undefined behavior. AnyInvocable() noexcept = default; AnyInvocable(std::nullptr_t) noexcept {} // NOLINT @@ -277,6 +284,8 @@ class AnyInvocable : private internal_any_invocable::Impl<Sig> { // In other words: // std::function<void()> f; // empty // absl::AnyInvocable<void()> a = std::move(f); // not empty + // + // Invoking an empty `AnyInvocable` results in undefined behavior. explicit operator bool() const noexcept { return this->HasValue(); } // Invokes the target object of `*this`. `*this` must not be empty. diff --git a/absl/functional/internal/any_invocable.h b/absl/functional/internal/any_invocable.h index 5bb7d48a..ce58fd8c 100644 --- a/absl/functional/internal/any_invocable.h +++ b/absl/functional/internal/any_invocable.h @@ -39,7 +39,7 @@ // target object, directly returning the result. // // // // When in the logically empty state, the manager function is an empty // -// function and the invoker function is one that would be undefined-behavior // +// function and the invoker function is one that would be undefined behavior // // to call. // // // // An additional optimization is performed when converting from one // |