11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "clang/Lex/Lexer.h" 22 AST_MATCHER(Decl, isInStdNamespace) {
return Node.isInStdNamespace(); }
25 void InaccurateEraseCheck::registerMatchers(MatchFinder *Finder) {
28 if (!getLangOpts().CPlusPlus)
33 callee(functionDecl(hasAnyName(
"remove",
"remove_if",
"unique"))),
36 anyOf(cxxConstructExpr(has(ignoringImplicit(
37 cxxMemberCallExpr(callee(cxxMethodDecl(hasName(
"end"))))
42 const auto DeclInStd = type(hasUnqualifiedDesugaredType(
43 tagType(hasDeclaration(decl(isInStdNamespace())))));
46 on(anyOf(hasType(DeclInStd), hasType(pointsTo(DeclInStd)))),
47 callee(cxxMethodDecl(hasName(
"erase"))), argumentCountIs(1),
48 hasArgument(0, has(ignoringImplicit(
49 anyOf(EndCall, has(ignoringImplicit(EndCall)))))),
50 unless(isInTemplateInstantiation()))
55 void InaccurateEraseCheck::check(
const MatchFinder::MatchResult &Result) {
56 const auto *MemberCall =
57 Result.Nodes.getNodeAs<CXXMemberCallExpr>(
"erase");
59 Result.Nodes.getNodeAs<CXXMemberCallExpr>(
"end");
60 const SourceLocation
Loc = MemberCall->getLocStart();
64 if (!Loc.isMacroID() && EndExpr) {
65 const auto *AlgCall = Result.Nodes.getNodeAs<CallExpr>(
"alg");
66 std::string ReplacementText = Lexer::getSourceText(
67 CharSourceRange::getTokenRange(EndExpr->getSourceRange()),
68 *Result.SourceManager, getLangOpts());
69 const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
70 AlgCall->getLocEnd(), 0, *Result.SourceManager, getLangOpts());
71 Hint = FixItHint::CreateInsertion(EndLoc,
", " + ReplacementText);
74 diag(Loc,
"this call will remove at most one item even when multiple items " SourceLocation Loc
'#' location in the include directive
AST_MATCHER(BinaryOperator, isAssignmentOperator)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//