11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 20 void UseUncaughtExceptionsCheck::registerMatchers(MatchFinder *Finder) {
21 if (!getLangOpts().CPlusPlus17)
24 std::string MatchText =
"::std::uncaught_exception";
28 usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(hasName(MatchText))))
34 declRefExpr(to(functionDecl(hasName(MatchText))), unless(callExpr()))
35 .bind(
"decl_ref_expr"),
39 Finder->addMatcher(callExpr(hasDeclaration(functionDecl(hasName(MatchText))),
40 unless(hasAncestor(initListExpr())))
45 Finder->addMatcher(callExpr(hasAncestor(initListExpr()),
46 hasDeclaration(functionDecl(hasName(MatchText))))
47 .bind(
"init_call_expr"),
51 void UseUncaughtExceptionsCheck::check(
const MatchFinder::MatchResult &
Result) {
52 SourceLocation BeginLoc;
53 SourceLocation EndLoc;
54 const CallExpr *C = Result.Nodes.getNodeAs<CallExpr>(
"init_call_expr");
55 bool WarnOnly =
false;
58 BeginLoc = C->getBeginLoc();
59 EndLoc = C->getEndLoc();
60 }
else if (
const auto *E = Result.Nodes.getNodeAs<CallExpr>(
"call_expr")) {
61 BeginLoc = E->getBeginLoc();
62 EndLoc = E->getEndLoc();
63 }
else if (
const auto *
D =
64 Result.Nodes.getNodeAs<DeclRefExpr>(
"decl_ref_expr")) {
65 BeginLoc =
D->getBeginLoc();
66 EndLoc =
D->getEndLoc();
69 const auto *U = Result.Nodes.getNodeAs<UsingDecl>(
"using_decl");
70 assert(U &&
"Null pointer, no node provided");
71 BeginLoc = U->getNameInfo().getBeginLoc();
72 EndLoc = U->getNameInfo().getEndLoc();
75 auto Diag = diag(BeginLoc,
"'std::uncaught_exception' is deprecated, use " 76 "'std::uncaught_exceptions' instead");
78 if (!BeginLoc.isMacroID()) {
80 Lexer::getSourceText(CharSourceRange::getTokenRange(BeginLoc, EndLoc),
81 *Result.SourceManager, getLangOpts());
83 Text.consume_back(
"()");
84 int TextLength = Text.size();
91 Diag << FixItHint::CreateInsertion(BeginLoc.getLocWithOffset(TextLength),
94 Diag << FixItHint::CreateReplacement(C->getSourceRange(),
95 "std::uncaught_exceptions() > 0");
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//