aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhalyavin <halyavin@yandex-team.com>2022-08-05 13:16:26 +0300
committerhalyavin <halyavin@yandex-team.com>2022-08-05 13:16:26 +0300
commit68d8479d07e0b689ba126cf2c159ae7f11afb9cf (patch)
tree92289178ebded927b8369e4eb1c931be730c6333
parentf346528af256244b692e713a8b6891957ae58dc6 (diff)
downloadydb-68d8479d07e0b689ba126cf2c159ae7f11afb9cf.tar.gz
Mark clear and reset methods as reinitializing the object.
This means, that moved-from object can be safely used after the call of such method. This attribute is used by clang-tidy which checks that moved-from objects are not used unless a reinitialization method is called first.
-rw-r--r--contrib/libs/cxxsupp/libcxx/include/__config6
-rw-r--r--contrib/libs/cxxsupp/libcxx/include/deque3
-rw-r--r--contrib/libs/cxxsupp/libcxx/include/map4
-rw-r--r--contrib/libs/cxxsupp/libcxx/include/set4
-rw-r--r--contrib/libs/cxxsupp/libcxx/include/vector4
-rw-r--r--util/generic/buffer.h3
-rw-r--r--util/generic/hash.h19
-rw-r--r--util/generic/hash_set.h14
-rw-r--r--util/generic/maybe.h3
-rw-r--r--util/generic/ptr.h33
-rw-r--r--util/generic/string.h3
-rw-r--r--util/system/compiler.h6
12 files changed, 61 insertions, 41 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/__config b/contrib/libs/cxxsupp/libcxx/include/__config
index 1984c01ed73..3f383a82d01 100644
--- a/contrib/libs/cxxsupp/libcxx/include/__config
+++ b/contrib/libs/cxxsupp/libcxx/include/__config
@@ -1325,6 +1325,12 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
# define _LIBCPP_FALLTHROUGH() ((void)0)
#endif
+#if defined(_LIBCPP_COMPILER_CLANG_BASED)
+# define _LIBCPP_REINITIALIZES_OBJECT [[clang::reinitializes]]
+#else
+# define _LIBCPP_REINITIALIZES_OBJECT
+#endif
+
#if __has_attribute(__nodebug__) && !defined(__CUDACC__)
#define _LIBCPP_NODEBUG __attribute__((__nodebug__))
#else
diff --git a/contrib/libs/cxxsupp/libcxx/include/deque b/contrib/libs/cxxsupp/libcxx/include/deque
index 50a8b381534..a4ab230742f 100644
--- a/contrib/libs/cxxsupp/libcxx/include/deque
+++ b/contrib/libs/cxxsupp/libcxx/include/deque
@@ -1467,7 +1467,7 @@ public:
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value);
#endif
- _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_REINITIALIZES_OBJECT _LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
@@ -2948,6 +2948,7 @@ deque<_Tp, _Allocator>::swap(deque& __c)
}
template <class _Tp, class _Allocator>
+_LIBCPP_REINITIALIZES_OBJECT
inline
void
deque<_Tp, _Allocator>::clear() _NOEXCEPT
diff --git a/contrib/libs/cxxsupp/libcxx/include/map b/contrib/libs/cxxsupp/libcxx/include/map
index aaf4b616209..d6a5ad1fa4b 100644
--- a/contrib/libs/cxxsupp/libcxx/include/map
+++ b/contrib/libs/cxxsupp/libcxx/include/map
@@ -1370,7 +1370,7 @@ public:
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __f, const_iterator __l)
{return __tree_.erase(__f.__i_, __l.__i_);}
- _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_REINITIALIZES_OBJECT _LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT {__tree_.clear();}
#if _LIBCPP_STD_VER > 14
@@ -2112,7 +2112,7 @@ public:
}
#endif
- _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_REINITIALIZES_OBJECT _LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT {__tree_.clear();}
_LIBCPP_INLINE_VISIBILITY
diff --git a/contrib/libs/cxxsupp/libcxx/include/set b/contrib/libs/cxxsupp/libcxx/include/set
index 04b6f52c084..99a061a0387 100644
--- a/contrib/libs/cxxsupp/libcxx/include/set
+++ b/contrib/libs/cxxsupp/libcxx/include/set
@@ -745,7 +745,7 @@ public:
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __f, const_iterator __l)
{return __tree_.erase(__f, __l);}
- _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_REINITIALIZES_OBJECT _LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT {__tree_.clear();}
#if _LIBCPP_STD_VER > 14
@@ -1276,7 +1276,7 @@ public:
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __f, const_iterator __l)
{return __tree_.erase(__f, __l);}
- _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_REINITIALIZES_OBJECT _LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT {__tree_.clear();}
#if _LIBCPP_STD_VER > 14
diff --git a/contrib/libs/cxxsupp/libcxx/include/vector b/contrib/libs/cxxsupp/libcxx/include/vector
index 916eaa75b63..1a2a271058b 100644
--- a/contrib/libs/cxxsupp/libcxx/include/vector
+++ b/contrib/libs/cxxsupp/libcxx/include/vector
@@ -637,7 +637,7 @@ public:
_LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
iterator erase(const_iterator __first, const_iterator __last);
- _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_REINITIALIZES_OBJECT _LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT
{
size_type __old_size = size();
@@ -2352,7 +2352,7 @@ public:
_LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
iterator erase(const_iterator __first, const_iterator __last);
- _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_REINITIALIZES_OBJECT _LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT {__size_ = 0;}
void swap(vector&)
diff --git a/util/generic/buffer.h b/util/generic/buffer.h
index 95764674049..a5efe398ce7 100644
--- a/util/generic/buffer.h
+++ b/util/generic/buffer.h
@@ -4,6 +4,7 @@
#include <util/generic/fwd.h>
#include <util/system/align.h>
+#include <util/system/compiler.h>
#include <util/system/yassert.h>
#include <cstring>
@@ -46,7 +47,7 @@ public:
Pos_ -= n;
}
- inline void Reset() noexcept {
+ Y_REINITIALIZES_OBJECT inline void Reset() noexcept {
TBuffer().Swap(*this);
}
diff --git a/util/generic/hash.h b/util/generic/hash.h
index 81311cc1ee4..0e2a7cfd12f 100644
--- a/util/generic/hash.h
+++ b/util/generic/hash.h
@@ -4,6 +4,7 @@
#include "mapfindptr.h"
#include <util/memory/alloc.h>
+#include <util/system/compiler.h>
#include <util/system/type_name.h>
#include <util/system/yassert.h>
#include <util/str_stl.h>
@@ -820,7 +821,7 @@ public:
void erase(const_iterator first, const_iterator last);
bool reserve(size_type num_elements_hint);
- void basic_clear();
+ Y_REINITIALIZES_OBJECT void basic_clear();
/**
* Clears the hashtable without deallocating the nodes.
@@ -841,7 +842,7 @@ public:
template <class KeySaver>
int save_for_st(IOutputStream* stream, KeySaver& ks, sthash<int, int, THash<int>, TEqualTo<int>, typename KeySaver::TSizeType>* stHash = nullptr) const;
- void clear(size_type downsize) {
+ Y_REINITIALIZES_OBJECT void clear(size_type downsize) {
basic_clear();
if (downsize < buckets.size()) {
@@ -872,7 +873,7 @@ public:
* Alternatively, the user can call `basic_clear`, which doesn't do the
* downsizing.
*/
- void clear() {
+ Y_REINITIALIZES_OBJECT void clear() {
if (num_elements)
clear((num_elements * 2 + buckets.size()) / 3);
}
@@ -1715,13 +1716,13 @@ public:
void erase(iterator f, iterator l) {
rep.erase(f, l);
}
- void clear() {
+ Y_REINITIALIZES_OBJECT void clear() {
rep.clear();
}
- void clear(size_t downsize_hint) {
+ Y_REINITIALIZES_OBJECT void clear(size_t downsize_hint) {
rep.clear(downsize_hint);
}
- void basic_clear() {
+ Y_REINITIALIZES_OBJECT void basic_clear() {
rep.basic_clear();
}
void release_nodes() {
@@ -1981,13 +1982,13 @@ public:
void erase(iterator f, iterator l) {
rep.erase(f, l);
}
- void clear() {
+ Y_REINITIALIZES_OBJECT void clear() {
rep.clear();
}
- void clear(size_t downsize_hint) {
+ Y_REINITIALIZES_OBJECT void clear(size_t downsize_hint) {
rep.clear(downsize_hint);
}
- void basic_clear() {
+ Y_REINITIALIZES_OBJECT void basic_clear() {
rep.basic_clear();
}
void release_nodes() {
diff --git a/util/generic/hash_set.h b/util/generic/hash_set.h
index e8088cf23b4..fd8851c2993 100644
--- a/util/generic/hash_set.h
+++ b/util/generic/hash_set.h
@@ -3,6 +3,8 @@
#include "fwd.h"
#include "hash.h"
+#include <util/system/compiler.h>
+
#include <initializer_list>
#include <utility>
@@ -227,13 +229,13 @@ public:
void erase(iterator f, iterator l) {
rep.erase(f, l);
}
- void clear() {
+ Y_REINITIALIZES_OBJECT void clear() {
rep.clear();
}
- void clear(size_t downsize_hint) {
+ Y_REINITIALIZES_OBJECT void clear(size_t downsize_hint) {
rep.clear(downsize_hint);
}
- void basic_clear() {
+ Y_REINITIALIZES_OBJECT void basic_clear() {
rep.basic_clear();
}
void release_nodes() {
@@ -435,13 +437,13 @@ public:
void erase(iterator f, iterator l) {
rep.erase(f, l);
}
- void clear() {
+ Y_REINITIALIZES_OBJECT void clear() {
rep.clear();
}
- void clear(size_t downsize_hint) {
+ Y_REINITIALIZES_OBJECT void clear(size_t downsize_hint) {
rep.clear(downsize_hint);
}
- void basic_clear() {
+ Y_REINITIALIZES_OBJECT void basic_clear() {
rep.basic_clear();
}
void release_nodes() {
diff --git a/util/generic/maybe.h b/util/generic/maybe.h
index 34d21aebcdc..633eb1b8435 100644
--- a/util/generic/maybe.h
+++ b/util/generic/maybe.h
@@ -6,6 +6,7 @@
#include "yexception.h"
#include <util/system/align.h>
+#include <util/system/compiler.h>
#include <util/stream/output.h>
#include <util/ysaveload.h>
@@ -284,7 +285,7 @@ public:
return *Data();
}
- void Clear() noexcept {
+ Y_REINITIALIZES_OBJECT void Clear() noexcept {
if (Defined()) {
this->Defined_ = false;
Data()->~T();
diff --git a/util/generic/ptr.h b/util/generic/ptr.h
index db076e7e113..3addc85753e 100644
--- a/util/generic/ptr.h
+++ b/util/generic/ptr.h
@@ -9,8 +9,9 @@
#include <utility>
-#include <util/system/yassert.h>
+#include <util/system/compiler.h>
#include <util/system/defaults.h>
+#include <util/system/yassert.h>
template <class T, class U>
using TGuardConversion = typename std::enable_if_t<std::is_convertible<U*, T*>::value>;
@@ -189,14 +190,14 @@ public:
return this->DoRelease(T_);
}
- inline void Reset(T* t) noexcept {
+ Y_REINITIALIZES_OBJECT inline void Reset(T* t) noexcept {
if (T_ != t) {
DoDestroy();
T_ = t;
}
}
- inline void Reset() noexcept {
+ Y_REINITIALIZES_OBJECT inline void Reset() noexcept {
Destroy();
}
@@ -284,18 +285,18 @@ public:
return this->DoRelease(T_);
}
- inline void Reset(T* t) noexcept {
+ Y_REINITIALIZES_OBJECT inline void Reset(T* t) noexcept {
if (T_ != t) {
DoDestroy();
T_ = t;
}
}
- inline void Reset(TAutoPtr<T, D> t) noexcept {
+ Y_REINITIALIZES_OBJECT inline void Reset(TAutoPtr<T, D> t) noexcept {
Reset(t.Release());
}
- inline void Reset() noexcept {
+ Y_REINITIALIZES_OBJECT inline void Reset() noexcept {
Destroy();
}
@@ -546,11 +547,11 @@ public:
// Effectively replace both:
// Reset(const TIntrusivePtr&)
// Reset(TIntrusivePtr&&)
- inline void Reset(TIntrusivePtr t) noexcept {
+ Y_REINITIALIZES_OBJECT inline void Reset(TIntrusivePtr t) noexcept {
Swap(t);
}
- inline void Reset() noexcept {
+ Y_REINITIALIZES_OBJECT inline void Reset() noexcept {
Drop();
}
@@ -666,11 +667,11 @@ public:
// Effectively replace both:
// Reset(const TIntrusiveConstPtr&)
// Reset(TIntrusiveConstPtr&&)
- inline void Reset(TIntrusiveConstPtr t) noexcept {
+ Y_REINITIALIZES_OBJECT inline void Reset(TIntrusiveConstPtr t) noexcept {
Swap(t);
}
- inline void Reset() noexcept {
+ Y_REINITIALIZES_OBJECT inline void Reset() noexcept {
Drop();
}
@@ -865,11 +866,11 @@ public:
// Effectively replace both:
// Reset(const TSharedPtr& t)
// Reset(TSharedPtr&& t)
- inline void Reset(TSharedPtr t) noexcept {
+ Y_REINITIALIZES_OBJECT inline void Reset(TSharedPtr t) noexcept {
Swap(t);
}
- inline void Reset() noexcept {
+ Y_REINITIALIZES_OBJECT inline void Reset() noexcept {
Drop();
}
@@ -1015,14 +1016,14 @@ public:
return DoRelease(T_);
}
- inline void Reset(T* t) noexcept {
+ Y_REINITIALIZES_OBJECT inline void Reset(T* t) noexcept {
if (T_ != t) {
DoDestroy();
T_ = t;
}
}
- inline void Reset() noexcept {
+ Y_REINITIALIZES_OBJECT inline void Reset() noexcept {
Destroy();
}
@@ -1094,11 +1095,11 @@ public:
T_.Swap(r.T_);
}
- inline void Reset(TCowPtr p) {
+ Y_REINITIALIZES_OBJECT inline void Reset(TCowPtr p) {
p.Swap(*this);
}
- inline void Reset() {
+ Y_REINITIALIZES_OBJECT inline void Reset() {
T_.Reset();
}
diff --git a/util/generic/string.h b/util/generic/string.h
index fedde9e787d..5f569544816 100644
--- a/util/generic/string.h
+++ b/util/generic/string.h
@@ -8,6 +8,7 @@
#include <string>
#include <string_view>
+#include <util/system/compiler.h>
#include <util/system/yassert.h>
#include "ptr.h"
@@ -561,7 +562,7 @@ private:
}
public:
- inline void clear() noexcept {
+ Y_REINITIALIZES_OBJECT inline void clear() noexcept {
#ifdef TSTRING_IS_STD_STRING
Storage_.clear();
#else
diff --git a/util/system/compiler.h b/util/system/compiler.h
index ba8ea4e3b70..d2054465977 100644
--- a/util/system/compiler.h
+++ b/util/system/compiler.h
@@ -636,6 +636,12 @@ _YandexAbort();
} while (0)
#endif
+#if defined(__clang__)
+ #define Y_REINITIALIZES_OBJECT [[clang::reinitializes]]
+#else
+ #define Y_REINITIALIZES_OBJECT
+#endif
+
#ifdef __cplusplus
void UseCharPointerImpl(volatile const char*);