10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 19 void UseUncaughtExceptionsCheck::registerMatchers(MatchFinder *Finder) {
20 if (!getLangOpts().CPlusPlus17)
23 std::string MatchText =
"::std::uncaught_exception";
27 usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(hasName(MatchText))))
33 declRefExpr(to(functionDecl(hasName(MatchText))), unless(callExpr()))
34 .bind(
"decl_ref_expr"),
38 Finder->addMatcher(callExpr(hasDeclaration(functionDecl(hasName(MatchText))),
39 unless(hasAncestor(initListExpr())))
44 Finder->addMatcher(callExpr(hasAncestor(initListExpr()),
45 hasDeclaration(functionDecl(hasName(MatchText))))
46 .bind(
"init_call_expr"),
50 void UseUncaughtExceptionsCheck::check(
const MatchFinder::MatchResult &
Result) {
51 SourceLocation BeginLoc;
52 SourceLocation EndLoc;
53 const CallExpr *C = Result.Nodes.getNodeAs<CallExpr>(
"init_call_expr");
54 bool WarnOnly =
false;
57 BeginLoc = C->getBeginLoc();
58 EndLoc = C->getEndLoc();
59 }
else if (
const auto *E = Result.Nodes.getNodeAs<CallExpr>(
"call_expr")) {
60 BeginLoc = E->getBeginLoc();
61 EndLoc = E->getEndLoc();
62 }
else if (
const auto *
D =
63 Result.Nodes.getNodeAs<DeclRefExpr>(
"decl_ref_expr")) {
64 BeginLoc =
D->getBeginLoc();
65 EndLoc =
D->getEndLoc();
68 const auto *U = Result.Nodes.getNodeAs<UsingDecl>(
"using_decl");
69 assert(U &&
"Null pointer, no node provided");
70 BeginLoc = U->getNameInfo().getBeginLoc();
71 EndLoc = U->getNameInfo().getEndLoc();
74 auto Diag = diag(BeginLoc,
"'std::uncaught_exception' is deprecated, use " 75 "'std::uncaught_exceptions' instead");
77 if (!BeginLoc.isMacroID()) {
80 *Result.SourceManager, getLangOpts());
82 Text.consume_back(
"()");
83 int TextLength = Text.size();
90 Diag << FixItHint::CreateInsertion(BeginLoc.getLocWithOffset(TextLength),
93 Diag << FixItHint::CreateReplacement(C->getSourceRange(),
94 "std::uncaught_exceptions() > 0");
llvm::Optional< Range > getTokenRange(const SourceManager &SM, const LangOptions &LangOpts, SourceLocation TokLoc)
Returns the taken range at TokLoc.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result