From d6df769173bf0263489f98874b93034db0e479a2 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 28 Aug 2018 01:05:21 -0700 Subject: Export of internal Abseil changes. -- de82143f509d8fd6e70efc9eaed35582054a7443 by Abseil Team : Mark optional::reset() with the ABSL_ATTRIBUTE_REINITIALIZES attribute. This prevents false positives in the clang-tidy check bugprone-use-after-move; it allows reset() to be called on a moved-from optional without any warnings, and the optional will thereafter be regarded as initialized again. PiperOrigin-RevId: 210502364 -- e645e68c44df957271e109aca6d68af530e27d04 by Derek Mauro : Mark //absl/synchronization:thread_pool as only visible to internal Abseil targets since it is internal-only. PiperOrigin-RevId: 210406260 -- 09b53240efba9bf73190eaea91fe33b9eafc3529 by Abseil Team : Add support for the [[clang::reinitializes]] attribute. This will be used to prevent false positives in the clang-tidy check bugprone-use-after-move. PiperOrigin-RevId: 210377317 GitOrigin-RevId: de82143f509d8fd6e70efc9eaed35582054a7443 Change-Id: Ibac1ee694f7b5b9f5aff8670559e49505ff8ee11 --- absl/base/attributes.h | 14 ++++++++++++++ absl/synchronization/BUILD.bazel | 3 +++ absl/types/optional.h | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/absl/base/attributes.h b/absl/base/attributes.h index 3662f0fe..cc933bba 100644 --- a/absl/base/attributes.h +++ b/absl/base/attributes.h @@ -494,6 +494,20 @@ #define ABSL_XRAY_LOG_ARGS(N) #endif +// ABSL_ATTRIBUTE_REINITIALIZES +// +// Indicates that a member function reinitializes the entire object to a known +// state, independent of the previous state of the object. +// +// The clang-tidy check bugprone-use-after-move allows member functions marked +// with this attribute to be called on objects that have been moved from; +// without the attribute, this would result in a use-after-move warning. +#if ABSL_HAVE_CPP_ATTRIBUTE(clang::reinitializes) +#define ABSL_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]] +#else +#define ABSL_ATTRIBUTE_REINITIALIZES +#endif + // ----------------------------------------------------------------------------- // Variable Attributes // ----------------------------------------------------------------------------- diff --git a/absl/synchronization/BUILD.bazel b/absl/synchronization/BUILD.bazel index 3ee9e5a0..4f6a7074 100644 --- a/absl/synchronization/BUILD.bazel +++ b/absl/synchronization/BUILD.bazel @@ -138,6 +138,9 @@ cc_library( name = "thread_pool", testonly = 1, hdrs = ["internal/thread_pool.h"], + visibility = [ + "//absl:__subpackages__", + ], deps = [ ":synchronization", "//absl/base:core_headers", diff --git a/absl/types/optional.h b/absl/types/optional.h index 79475e3e..14210018 100644 --- a/absl/types/optional.h +++ b/absl/types/optional.h @@ -59,6 +59,7 @@ using std::nullopt; #include #include +#include "absl/base/attributes.h" #include "absl/memory/memory.h" #include "absl/meta/type_traits.h" #include "absl/types/bad_optional_access.h" @@ -700,7 +701,7 @@ class optional : private optional_internal::optional_data, // optional::reset() // // Destroys the inner `T` value of an `absl::optional` if one is present. - void reset() noexcept { this->destruct(); } + ABSL_ATTRIBUTE_REINITIALIZES void reset() noexcept { this->destruct(); } // optional::emplace() // -- cgit v1.2.3