[clang-tools-extra] Extend bugprone-use-after-move check to handle std::optional::reset() and std::any::reset() (PR #114255)

via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 30 09:05:57 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff a78861fc55d18046989ff4d624a037e9181da170 2d907aa6453b43a2bb537cf1eb32d7f3f8a850a7 --extensions cpp -- clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
index 0758707a9e..38ca539efd 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -256,8 +256,8 @@ bool isStandardResettable(const ValueDecl *VD) {
     return false;
 
   StringRef Name = ID->getName();
-  if (Name != "unique_ptr" && Name != "shared_ptr" && Name != "weak_ptr" && Name != "optional" &&
-      Name != "any")
+  if (Name != "unique_ptr" && Name != "shared_ptr" && Name != "weak_ptr" &&
+      Name != "optional" && Name != "any")
     return false;
 
   return RecordDecl->getDeclContext()->isStdNamespace();
@@ -316,10 +316,10 @@ void UseAfterMoveFinder::getReinits(
           "::std::unordered_map", "::std::unordered_multiset",
           "::std::unordered_multimap"))))));
 
-  auto StandardResettableTypeMatcher = hasType(hasUnqualifiedDesugaredType(
-      recordType(hasDeclaration(cxxRecordDecl(hasAnyName(
-          "::std::unique_ptr", "::std::shared_ptr", "::std::weak_ptr", "::std::optional",
-          "::std::any"))))));
+  auto StandardResettableTypeMatcher = hasType(
+      hasUnqualifiedDesugaredType(recordType(hasDeclaration(cxxRecordDecl(
+          hasAnyName("::std::unique_ptr", "::std::shared_ptr",
+                     "::std::weak_ptr", "::std::optional", "::std::any"))))));
 
   // Matches different types of reinitialization.
   auto ReinitMatcher =

``````````

</details>


https://github.com/llvm/llvm-project/pull/114255


More information about the cfe-commits mailing list