[PATCH] D52451: Add macro LLVM_ATTRIBUTE_REINITIALIZES

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 24 21:59:38 PDT 2018


MaskRay created this revision.
MaskRay added reviewers: aaron.ballman, rsmith, mboehme, hokein.
Herald added subscribers: llvm-commits, kristina.

This marks legitimate use-after-move (e.g. `Found.clear()` in https://reviews.llvm.org/rC342925)
which would otherwise be caught by bugprone-use-after-move.

bugprone-use-after-move recognizes this attribute after https://reviews.llvm.org/rCTE339571.


Repository:
  rL LLVM

https://reviews.llvm.org/D52451

Files:
  include/llvm/Support/Compiler.h


Index: include/llvm/Support/Compiler.h
===================================================================
--- include/llvm/Support/Compiler.h
+++ include/llvm/Support/Compiler.h
@@ -133,6 +133,19 @@
 #define LLVM_NODISCARD
 #endif
 
+// Indicate that a non-static, non-const C++ 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 recognizes this attribute as a
+// marker that a moved-from object has left the indeterminate state and can be
+// reused.
+#if __has_cpp_attribute(clang::reinitializes)
+#define LLVM_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]]
+#else
+#define LLVM_ATTRIBUTE_REINITIALIZES
+#endif
+
 // Some compilers warn about unused functions. When a function is sometimes
 // used or not depending on build settings (e.g. a function only called from
 // within "assert"), this attribute can be used to suppress such warnings.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52451.166804.patch
Type: text/x-patch
Size: 975 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180925/bd8f7ad4/attachment.bin>


More information about the llvm-commits mailing list