Author: serge-sans-paille
Date: 2026-03-16T11:38:47Z
New Revision: bec741cd753d1be06da8ecdc7d9048453b7675d5

URL: 
https://github.com/llvm/llvm-project/commit/bec741cd753d1be06da8ecdc7d9048453b7675d5
DIFF: 
https://github.com/llvm/llvm-project/commit/bec741cd753d1be06da8ecdc7d9048453b7675d5.diff

LOG: [clang-tidy] Fix performance-use-std-move when moving a forward decl 
(#186704)

This fixes running clang-tidy on top-of-tree with that check on.

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/performance/UseStdMoveCheck.cpp
    clang-tools-extra/test/clang-tidy/checkers/performance/use-std-move.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/performance/UseStdMoveCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/UseStdMoveCheck.cpp
index 2a7df4142a6de..7c3bbc3187cd9 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 CXXRecordDecl *ND = Node.getDefinition();
+  if (!ND)
     return false;
-  for (const auto *CM : Node.methods())
+  if (!ND->hasNonTrivialMoveAssignment())
+    return false;
+  for (const CXXMethodDecl *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
 // -----------------------------------------------------------
 


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to