[clang-tools-extra] [clang-tidy] Fix performance-use-std-move when moving a forward decla… (PR #186704)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 15 14:16:55 PDT 2026
https://github.com/serge-sans-paille created https://github.com/llvm/llvm-project/pull/186704
…red type within the type definition
>From cb5f30a35a744ba2a67b641145cff32d8b06fc5a Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sguelton at mozilla.com>
Date: Sun, 15 Mar 2026 22:15:18 +0100
Subject: [PATCH] [clang-tidy] Fix performance-use-std-move when moving a
forward declared type within the type definition
---
.../clang-tidy/performance/UseStdMoveCheck.cpp | 7 +++++--
.../checkers/performance/use-std-move.cpp | 15 +++++++++++++++
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/performance/UseStdMoveCheck.cpp b/clang-tools-extra/clang-tidy/performance/UseStdMoveCheck.cpp
index 2a7df4142a6de..a97698d1f518c 100644
--- a/clang-tools-extra/clang-tidy/performance/UseStdMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/UseStdMoveCheck.cpp
@@ -24,9 +24,12 @@ namespace clang::tidy::performance {
namespace {
AST_MATCHER(CXXRecordDecl, hasAccessibleNonTrivialMoveAssignment) {
- if (!Node.hasNonTrivialMoveAssignment())
+ const auto *ND = Node.getDefinition();
+ if (!ND)
return false;
- for (const auto *CM : Node.methods())
+ if (!ND->hasNonTrivialMoveAssignment())
+ return false;
+ for (const auto *CM : ND->methods())
if (CM->isMoveAssignmentOperator())
return !CM->isDeleted() && CM->getAccess() == AS_public;
llvm_unreachable("Move Assignment Operator Not Found");
diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/use-std-move.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/use-std-move.cpp
index c7014859adf50..87a5c90030d8f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/performance/use-std-move.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/performance/use-std-move.cpp
@@ -289,6 +289,21 @@ void NonConvertibleNonTrivialMoveAssignInLoop(NonTrivialMoveAssign& target, NonT
target = source;
}
+// Check moving incomplete definition
+// ----------------------------------
+
+struct fwd_cls;
+struct fwd_cls {
+ void ConvertibleNonTrivialMoveAssignReferecingForwardDecl(fwd_cls src) {
+ // CHECK-MESSAGES: [[@LINE+2]]:13: warning: 'src' could be moved here [performance-use-std-move]
+ // CHECK-FIXES: *this = std::move(src);
+ *this = src;
+ }
+ fwd_cls &operator=(const fwd_cls &C);
+ fwd_cls &operator=(fwd_cls &&);
+};
+
+
// Check moving for invalid / non profitable type or operation
// -----------------------------------------------------------
More information about the cfe-commits
mailing list