45 const auto *OuterCall = Result.Nodes.getNodeAs<CallExpr>(
"outer_call");
48 const auto *InnerCall = Result.Nodes.getNodeAs<CallExpr>(
"inner_call");
51 const auto *OuterCallee =
52 cast<DeclRefExpr>(OuterCall->getCallee()->IgnoreImplicit());
54 const StringRef InnerFuncName =
55 cast<NamedDecl>(InnerCall->getCalleeDecl())->getName();
58 const llvm::SmallDenseMap<StringRef, StringRef, 2>
59 InnerFuncNameToReplacementFuncName = {
60 {
"map_range",
"map_to_vector"},
61 {
"make_filter_range",
"filter_to_vector"},
63 const StringRef ReplacementFuncName =
64 InnerFuncNameToReplacementFuncName.lookup(InnerFuncName);
65 assert(!ReplacementFuncName.empty() &&
"Unhandled function?");
67 const auto Diag = diag(OuterCall->getBeginLoc(),
"use '%0'")
68 << ReplacementFuncName;
78 const SourceManager &SM = *Result.SourceManager;
79 const std::optional<Token> InnerLParen =
81 InnerCall->getCallee()->getEndLoc(), SM, getLangOpts());
82 if (!InnerLParen || InnerLParen->isNot(tok::l_paren))
85 Diag << FixItHint::CreateReplacement(
86 OuterCallee->getNameInfo().getSourceRange(), ReplacementFuncName)
87 << FixItHint::CreateRemoval(CharSourceRange::getCharRange(
88 InnerCall->getBeginLoc(), InnerLParen->getEndLoc()))
89 << FixItHint::CreateRemoval(InnerCall->getRParenLoc());
92 if (
auto IncludeFixit = Inserter.createIncludeInsertion(
93 SM.getFileID(OuterCall->getBeginLoc()),
94 "llvm/ADT/SmallVectorExtras.h"))
95 Diag << *IncludeFixit;
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.