11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "llvm/ADT/SmallSet.h" 14 #include "llvm/ADT/StringSet.h" 21 FunctionsThatShouldNotThrow) {
22 return FunctionsThatShouldNotThrow.count(Node.getNameAsString()) > 0;
28 ExceptionEscapeCheck::ExceptionEscapeCheck(StringRef
Name,
30 :
ClangTidyCheck(Name, Context), RawFunctionsThatShouldNotThrow(Options.get(
31 "FunctionsThatShouldNotThrow",
"")),
32 RawIgnoredExceptions(Options.get(
"IgnoredExceptions",
"")) {
33 llvm::SmallVector<StringRef, 8> FunctionsThatShouldNotThrowVec,
35 StringRef(RawFunctionsThatShouldNotThrow)
36 .split(FunctionsThatShouldNotThrowVec,
",", -1,
false);
37 FunctionsThatShouldNotThrow.insert(FunctionsThatShouldNotThrowVec.begin(),
38 FunctionsThatShouldNotThrowVec.end());
40 llvm::StringSet<> IgnoredExceptions;
41 StringRef(RawIgnoredExceptions).split(IgnoredExceptionsVec,
",", -1,
false);
42 IgnoredExceptions.insert(IgnoredExceptionsVec.begin(),
43 IgnoredExceptionsVec.end());
50 RawFunctionsThatShouldNotThrow);
51 Options.
store(Opts,
"IgnoredExceptions", RawIgnoredExceptions);
59 functionDecl(anyOf(isNoThrow(), cxxDestructorDecl(),
60 cxxConstructorDecl(isMoveConstructor()),
61 cxxMethodDecl(isMoveAssignmentOperator()),
62 hasName(
"main"), hasName(
"swap"),
63 isEnabled(FunctionsThatShouldNotThrow)))
69 const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>(
"thrower");
78 diag(MatchedDecl->getLocation(),
79 "an exception may be thrown in function %0 " 81 "which should not throw exceptions")
Base class for all clang-tidy checks.
const LangOptions & getLangOpts() const
Returns the language options from the context.
State getBehaviour() const
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
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
The function can definitly throw given an AST.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
ExceptionInfo analyze(const FunctionDecl *Func)
void ignoreBadAlloc(bool ShallIgnore)
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void ignoreExceptions(llvm::StringSet<> ExceptionNames)
AST_MATCHER_P(CXXMethodDecl, hasCanonicalDecl, ast_matchers::internal::Matcher< CXXMethodDecl >, InnerMatcher)