[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.
This commit is contained in:
serge-sans-paille
2026-03-16 11:38:47 +00:00
committed by GitHub
parent a1054ec627
commit bec741cd75
2 changed files with 20 additions and 2 deletions

View File

@@ -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");

View File

@@ -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
// -----------------------------------------------------------