10 #include "../utils/Matchers.h"
11 #include "../utils/OptionsUtils.h"
12 #include "clang/AST/ASTContext.h"
13 #include "clang/ASTMatchers/ASTMatchFinder.h"
19 namespace performance {
21 NoAutomaticMoveCheck::NoAutomaticMoveCheck(StringRef
Name,
28 const auto ConstLocalVariable =
29 varDecl(hasLocalStorage(), unless(hasType(lValueReferenceType())),
33 unless(hasDeclaration(namedDecl(
34 matchers::matchesAnyListedName(AllowedTypes)))))))
39 const auto LValueRefCtor = cxxConstructorDecl(
41 hasType(lValueReferenceType(pointee(type().bind(
"SrcT"))))),
42 ofClass(cxxRecordDecl(hasMethod(cxxConstructorDecl(
43 hasParameter(0, hasType(rValueReferenceType(
44 pointee(type(equalsBoundNode(
"SrcT")))))))))));
47 traverse(ast_type_traits::TK_AsIs,
48 returnStmt(hasReturnValue(
49 ignoringElidableConstructorCall(ignoringParenImpCasts(
51 hasDeclaration(LValueRefCtor),
52 hasArgument(0, ignoringParenImpCasts(declRefExpr(
53 to(ConstLocalVariable)))))
54 .bind(
"ctor_call")))))),
59 const auto *Var = Result.Nodes.getNodeAs<VarDecl>(
"vardecl");
60 const auto *CtorCall = Result.Nodes.getNodeAs<Expr>(
"ctor_call");
61 diag(CtorCall->getExprLoc(),
"constness of '%0' prevents automatic move")