From adba5c44416a57200d31286c5c9cb7d71d2489ea Mon Sep 17 00:00:00 2001 From: ephphatha Date: Tue, 19 Apr 2022 16:15:41 +1000 Subject: [PATCH] Add hint to avoid bugprone-use-after-move warnings Makes clang (and GCC) consider item.Clear() a reinitialisation of a moved variable - see https://clang.llvm.org/extra/clang-tidy/checks/bugprone-use-after-move.html#reinitialization --- Source/cpp.hint | 7 +++++++ Source/items.h | 2 +- Source/utils/attributes.h | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 Source/cpp.hint diff --git a/Source/cpp.hint b/Source/cpp.hint new file mode 100644 index 000000000..dd5e956b9 --- /dev/null +++ b/Source/cpp.hint @@ -0,0 +1,7 @@ +// Hint files help the Visual Studio IDE interpret Visual C++ identifiers +// such as names of functions and macros. +// For more information see https://go.microsoft.com/fwlink/?linkid=865984 +#define DVL_ALWAYS_INLINE +#define DVL_ATTRIBUTE_HOT +#define DVL_API_FOR_TEST +#define DVL_REINITIALIZES diff --git a/Source/items.h b/Source/items.h index 15b5f9039..357c5889f 100644 --- a/Source/items.h +++ b/Source/items.h @@ -245,7 +245,7 @@ struct Item { /** * @brief Resets the item so isEmpty() returns true without needing to reinitialise the whole object */ - void Clear() + DVL_REINITIALIZES void Clear() { this->_itype = ItemType::None; } diff --git a/Source/utils/attributes.h b/Source/utils/attributes.h index 163545791..16214fd0d 100644 --- a/Source/utils/attributes.h +++ b/Source/utils/attributes.h @@ -42,3 +42,11 @@ #else #define DVL_API_FOR_TEST #endif + +#if defined(__clang__) +#define DVL_REINITIALIZES [[clang::reinitializes]] +#elif DVL_HAVE_ATTRIBUTE(reinitializes) +#define DVL_REINITIALIZES __attribute__((reinitializes)) +#else +#define DVL_REINITIALIZES +#endif