10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 12 #include "clang/Lex/Lexer.h" 20 void InaccurateEraseCheck::registerMatchers(MatchFinder *Finder) {
23 if (!getLangOpts().CPlusPlus)
28 callee(functionDecl(hasAnyName(
"remove",
"remove_if",
"unique"))),
31 anyOf(cxxConstructExpr(has(ignoringImplicit(
32 cxxMemberCallExpr(callee(cxxMethodDecl(hasName(
"end"))))
37 const auto DeclInStd = type(hasUnqualifiedDesugaredType(
38 tagType(hasDeclaration(decl(isInStdNamespace())))));
41 on(anyOf(hasType(DeclInStd), hasType(pointsTo(DeclInStd)))),
42 callee(cxxMethodDecl(hasName(
"erase"))), argumentCountIs(1),
43 hasArgument(0, has(ignoringImplicit(
44 anyOf(EndCall, has(ignoringImplicit(EndCall)))))),
45 unless(isInTemplateInstantiation()))
50 void InaccurateEraseCheck::check(
const MatchFinder::MatchResult &Result) {
51 const auto *MemberCall =
52 Result.Nodes.getNodeAs<CXXMemberCallExpr>(
"erase");
54 Result.Nodes.getNodeAs<CXXMemberCallExpr>(
"end");
55 const SourceLocation
Loc = MemberCall->getBeginLoc();
59 if (!Loc.isMacroID() && EndExpr) {
60 const auto *AlgCall = Result.Nodes.getNodeAs<CallExpr>(
"alg");
61 std::string ReplacementText = Lexer::getSourceText(
63 *Result.SourceManager, getLangOpts());
64 const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
65 AlgCall->getEndLoc(), 0, *Result.SourceManager, getLangOpts());
66 Hint = FixItHint::CreateInsertion(EndLoc,
", " + ReplacementText);
69 diag(Loc,
"this call will remove at most one item even when multiple items " SourceLocation Loc
'#' location in the include directive
llvm::Optional< Range > getTokenRange(const SourceManager &SM, const LangOptions &LangOpts, SourceLocation TokLoc)
Returns the taken range at TokLoc.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//