10 #include "clang/AST/ASTContext.h" 11 #include "clang/Lex/Lexer.h" 21 NoexceptMacro(Options.get(
"ReplacementString",
"")),
22 UseNoexceptFalse(Options.get(
"UseNoexceptFalse", true)) {}
26 Options.
store(Opts,
"UseNoexceptFalse", UseNoexceptFalse);
36 hasTypeLoc(loc(functionProtoType(hasDynamicExceptionSpec()))),
37 anyOf(hasOverloadedOperatorName(
"delete[]"),
38 hasOverloadedOperatorName(
"delete"), cxxDestructorDecl()))
45 hasTypeLoc(loc(functionProtoType(hasDynamicExceptionSpec()))),
46 unless(anyOf(hasOverloadedOperatorName(
"delete[]"),
47 hasOverloadedOperatorName(
"delete"),
48 cxxDestructorDecl())))
53 parmVarDecl(anyOf(hasType(pointerType(pointee(parenType(innerType(
54 functionProtoType(hasDynamicExceptionSpec())))))),
55 hasType(memberPointerType(pointee(parenType(innerType(
56 functionProtoType(hasDynamicExceptionSpec()))))))))
62 const FunctionProtoType *FnTy =
nullptr;
63 bool DtorOrOperatorDel =
false;
66 if (
const auto *FuncDecl = Result.Nodes.getNodeAs<FunctionDecl>(
"funcDecl")) {
67 DtorOrOperatorDel = Result.Nodes.getNodeAs<FunctionDecl>(
"del-dtor");
68 FnTy = FuncDecl->getType()->getAs<FunctionProtoType>();
69 if (
const auto *TSI = FuncDecl->getTypeSourceInfo())
71 TSI->getTypeLoc().castAs<FunctionTypeLoc>().getExceptionSpecRange();
72 }
else if (
const auto *ParmDecl =
73 Result.Nodes.getNodeAs<ParmVarDecl>(
"parmVarDecl")) {
74 FnTy = ParmDecl->getType()
77 ->getAs<FunctionProtoType>();
79 if (
const auto *TSI = ParmDecl->getTypeSourceInfo())
80 Range = TSI->getTypeLoc()
83 .castAs<FunctionProtoTypeLoc>()
84 .getExceptionSpecRange();
86 CharSourceRange CRange = Lexer::makeFileCharRange(
88 Result.Context->getLangOpts());
90 assert(FnTy &&
"FunctionProtoType is null.");
91 bool IsNoThrow = FnTy->isNothrow();
92 StringRef ReplacementStr =
94 ? NoexceptMacro.empty() ?
"noexcept" : NoexceptMacro.c_str()
95 : NoexceptMacro.empty()
96 ? (DtorOrOperatorDel || UseNoexceptFalse) ?
"noexcept(false)" 101 if ((IsNoThrow || NoexceptMacro.empty()) && CRange.isValid())
102 FixIt = FixItHint::CreateReplacement(CRange, ReplacementStr);
104 diag(Range.getBegin(),
"dynamic exception specification '%0' is deprecated; " 105 "consider %select{using '%2'|removing it}1 instead")
106 << Lexer::getSourceText(CRange, *Result.SourceManager,
107 Result.Context->getLangOpts())
108 << ReplacementStr.empty() << ReplacementStr <<
FixIt;
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Base class for all clang-tidy checks.
const LangOptions & getLangOpts() const
Returns the language options from the context.
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
static constexpr llvm::StringLiteral Name
std::map< std::string, std::string > OptionMap
llvm::Optional< Range > getTokenRange(const SourceManager &SM, const LangOptions &LangOpts, SourceLocation TokLoc)
Returns the taken range at TokLoc.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
CharSourceRange Range
SourceRange for the file name.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
llvm::Optional< FixItHint > FixIt
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.