summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorvadim-xd <[email protected]>2026-05-25 20:01:13 +0300
committervadim-xd <[email protected]>2026-05-25 20:27:47 +0300
commit392658765ac88bb34bbd0b2fef2f0658e4efdc44 (patch)
treebf855b5b995549ce2eacf524d637c4a6cfecc933 /util
parent022e2dfce8e0ab77b6c50cd1f440fe9d63bb8403 (diff)
Add Y_INITIALIZED (silencer for bugprone-use-after-move)
commit_hash:e683c92bdbc059b1f08f9a6239e9348849914e84
Diffstat (limited to 'util')
-rw-r--r--util/system/compiler.h23
-rw-r--r--util/system/compiler_ut.cpp11
2 files changed, 34 insertions, 0 deletions
diff --git a/util/system/compiler.h b/util/system/compiler.h
index f63225c81b7..033ddbd8bcd 100644
--- a/util/system/compiler.h
+++ b/util/system/compiler.h
@@ -223,6 +223,29 @@ constexpr Y_FORCE_INLINE int Y_UNUSED(Types&&...) {
#endif
/**
+ * @def Y_INITIALIZED
+ *
+ * This function can be used to silence erroneous bugprone-use-after-move warnings from clang-tidy.
+ * (see https://clang.llvm.org/extra/clang-tidy/checks/bugprone/use-after-move.html#silencing-erroneous-warnings)
+ *
+ * @code
+ * void Foo(T value, int i) {
+ * if (i == 1) {
+ * DoSomethingWith(std::move(value));
+ * }
+ * if (i == 2) {
+ * Y_INITIALIZED(value);
+ * DoOtherThingWith(std::move(value));
+ * }
+ * }
+ */
+#if defined(__cplusplus)
+template <class... Types>
+constexpr Y_FORCE_INLINE void Y_INITIALIZED(Types&...) {
+}
+#endif
+
+/**
* @def Y_ASSUME
*
* Macro that tells the compiler that it can generate optimized code
diff --git a/util/system/compiler_ut.cpp b/util/system/compiler_ut.cpp
index 3ee0f251d47..7e28e4adf86 100644
--- a/util/system/compiler_ut.cpp
+++ b/util/system/compiler_ut.cpp
@@ -2,6 +2,8 @@
#include <library/cpp/testing/unittest/registar.h>
+#include <string>
+
Y_UNIT_TEST_SUITE(TCompilerTest) {
Y_UNIT_TEST(TestPragmaNoWshadow) {
Y_PRAGMA_DIAGNOSTIC_PUSH
@@ -69,4 +71,13 @@ Y_UNIT_TEST_SUITE(TCompilerTest) {
Y_PRAGMA_DIAGNOSTIC_POP
}
+
+ Y_UNIT_TEST(TestYInitialized) {
+ std::string s;
+ if (false) {
+ auto _ = std::move(s);
+ }
+ Y_INITIALIZED(s); // not moved
+ Y_UNUSED(s.size()); // no bugprone-use-after-move warning
+ }
} // Y_UNIT_TEST_SUITE(TCompilerTest)