11 #include "clang/AST/ASTContext.h" 12 #include "clang/Lex/Lexer.h" 22 NoexceptMacro(Options.get(
"ReplacementString",
"")),
23 UseNoexceptFalse(Options.get(
"UseNoexceptFalse", true)) {}
27 Options.
store(Opts,
"UseNoexceptFalse", UseNoexceptFalse);
37 hasTypeLoc(loc(functionProtoType(hasDynamicExceptionSpec()))),
38 anyOf(hasOverloadedOperatorName(
"delete[]"),
39 hasOverloadedOperatorName(
"delete"), cxxDestructorDecl()))
46 hasTypeLoc(loc(functionProtoType(hasDynamicExceptionSpec()))),
47 unless(anyOf(hasOverloadedOperatorName(
"delete[]"),
48 hasOverloadedOperatorName(
"delete"),
49 cxxDestructorDecl())))
54 parmVarDecl(anyOf(hasType(pointerType(pointee(parenType(innerType(
55 functionProtoType(hasDynamicExceptionSpec())))))),
56 hasType(memberPointerType(pointee(parenType(innerType(
57 functionProtoType(hasDynamicExceptionSpec()))))))))
63 const FunctionProtoType *FnTy =
nullptr;
64 bool DtorOrOperatorDel =
false;
67 if (
const auto *FuncDecl = Result.Nodes.getNodeAs<FunctionDecl>(
"funcDecl")) {
68 DtorOrOperatorDel = Result.Nodes.getNodeAs<FunctionDecl>(
"del-dtor");
69 FnTy = FuncDecl->getType()->getAs<FunctionProtoType>();
70 if (
const auto *TSI = FuncDecl->getTypeSourceInfo())
72 TSI->getTypeLoc().castAs<FunctionTypeLoc>().getExceptionSpecRange();
73 }
else if (
const auto *ParmDecl =
74 Result.Nodes.getNodeAs<ParmVarDecl>(
"parmVarDecl")) {
75 FnTy = ParmDecl->getType()
78 ->getAs<FunctionProtoType>();
80 if (
const auto *TSI = ParmDecl->getTypeSourceInfo())
81 Range = TSI->getTypeLoc()
84 .castAs<FunctionProtoTypeLoc>()
85 .getExceptionSpecRange();
87 CharSourceRange CRange = Lexer::makeFileCharRange(
88 CharSourceRange::getTokenRange(Range), *Result.SourceManager,
89 Result.Context->getLangOpts());
91 assert(FnTy &&
"FunctionProtoType is null.");
92 bool IsNoThrow = FnTy->isNothrow();
93 StringRef ReplacementStr =
95 ? NoexceptMacro.empty() ?
"noexcept" : NoexceptMacro.c_str()
96 : NoexceptMacro.empty()
97 ? (DtorOrOperatorDel || UseNoexceptFalse) ?
"noexcept(false)" 102 if ((IsNoThrow || NoexceptMacro.empty()) && CRange.isValid())
103 FixIt = FixItHint::CreateReplacement(CRange, ReplacementStr);
105 diag(Range.getBegin(),
"dynamic exception specification '%0' is deprecated; " 106 "consider %select{using '%2'|removing it}1 instead")
107 << Lexer::getSourceText(CRange, *Result.SourceManager,
108 Result.Context->getLangOpts())
109 << ReplacementStr.empty() << ReplacementStr <<
FixIt;
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.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
LangOptions getLangOpts() const
Returns the language options from the context.
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.
static constexpr llvm::StringLiteral Name
std::map< std::string, std::string > OptionMap
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
===– 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.