18 std::string MatchText =
"::std::uncaught_exception";
22 usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(hasName(MatchText))))
28 declRefExpr(to(functionDecl(hasName(MatchText))), unless(callExpr()))
29 .bind(
"decl_ref_expr"),
32 auto DirectCallToUncaughtException = callee(expr(ignoringImpCasts(
33 declRefExpr(hasDeclaration(functionDecl(hasName(MatchText)))))));
36 Finder->addMatcher(callExpr(DirectCallToUncaughtException,
37 unless(hasAncestor(initListExpr())))
43 callExpr(DirectCallToUncaughtException, hasAncestor(initListExpr()))
44 .bind(
"init_call_expr"),
49 SourceLocation BeginLoc;
50 SourceLocation EndLoc;
51 const auto *C = Result.Nodes.getNodeAs<CallExpr>(
"init_call_expr");
52 bool WarnOnly =
false;
55 BeginLoc = C->getBeginLoc();
56 EndLoc = C->getEndLoc();
57 }
else if (
const auto *E = Result.Nodes.getNodeAs<CallExpr>(
"call_expr")) {
58 BeginLoc = E->getBeginLoc();
59 EndLoc = E->getEndLoc();
60 }
else if (
const auto *D =
61 Result.Nodes.getNodeAs<DeclRefExpr>(
"decl_ref_expr")) {
62 BeginLoc = D->getBeginLoc();
63 EndLoc = D->getEndLoc();
66 const auto *U = Result.Nodes.getNodeAs<UsingDecl>(
"using_decl");
67 assert(U &&
"Null pointer, no node provided");
68 BeginLoc = U->getNameInfo().getBeginLoc();
69 EndLoc = U->getNameInfo().getEndLoc();
72 auto Diag = diag(BeginLoc,
"'std::uncaught_exception' is deprecated, use "
73 "'std::uncaught_exceptions' instead");
75 if (!BeginLoc.isMacroID()) {
77 Lexer::getSourceText(CharSourceRange::getTokenRange(BeginLoc, EndLoc),
78 *Result.SourceManager, getLangOpts());
80 Text.consume_back(
"()");
81 int TextLength = Text.size();
88 Diag << FixItHint::CreateInsertion(BeginLoc.getLocWithOffset(TextLength),
91 Diag << FixItHint::CreateReplacement(C->getSourceRange(),
92 "std::uncaught_exceptions() > 0");