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))))
33 Finder->addMatcher(declRefExpr(allOf(to(functionDecl(hasName(MatchText))),
35 .bind(
"decl_ref_expr"),
40 callExpr(allOf(hasDeclaration(functionDecl(hasName(MatchText))),
41 unless(hasAncestor(initListExpr()))))
47 callExpr(allOf(hasAncestor(initListExpr()),
48 hasDeclaration(functionDecl(hasName(MatchText)))))
49 .bind(
"init_call_expr"),
53 void UseUncaughtExceptionsCheck::check(
const MatchFinder::MatchResult &Result) {
54 SourceLocation BeginLoc;
55 SourceLocation EndLoc;
56 const CallExpr *C = Result.Nodes.getNodeAs<CallExpr>(
"init_call_expr");
57 bool WarnOnly =
false;
60 BeginLoc = C->getLocStart();
61 EndLoc = C->getLocEnd();
62 }
else if (
const auto *E = Result.Nodes.getNodeAs<CallExpr>(
"call_expr")) {
63 BeginLoc = E->getLocStart();
64 EndLoc = E->getLocEnd();
65 }
else if (
const auto *D =
66 Result.Nodes.getNodeAs<DeclRefExpr>(
"decl_ref_expr")) {
67 BeginLoc = D->getLocStart();
68 EndLoc = D->getLocEnd();
71 const auto *U = Result.Nodes.getNodeAs<UsingDecl>(
"using_decl");
72 assert(U &&
"Null pointer, no node provided");
73 BeginLoc = U->getNameInfo().getBeginLoc();
74 EndLoc = U->getNameInfo().getEndLoc();
77 auto Diag = diag(BeginLoc,
"'std::uncaught_exception' is deprecated, use " 78 "'std::uncaught_exceptions' instead");
80 if (!BeginLoc.isMacroID()) {
82 Lexer::getSourceText(CharSourceRange::getTokenRange(BeginLoc, EndLoc),
83 *Result.SourceManager, getLangOpts());
85 Text.consume_back(
"()");
86 int TextLength = Text.size();
93 Diag << FixItHint::CreateInsertion(BeginLoc.getLocWithOffset(TextLength),
96 Diag << FixItHint::CreateReplacement(C->getSourceRange(),
97 "std::uncaught_exceptions() > 0");
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//