11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
13#include "llvm/ADT/SmallSet.h"
14#include "llvm/ADT/StringSet.h"
22 FunctionsThatShouldNotThrow) {
23 return FunctionsThatShouldNotThrow.count(
Node.getNameAsString()) > 0;
27 return isExplicitThrowExceptionSpec(
Node.getExceptionSpecType()) &&
28 Node.getExceptionSpecSourceRange().isValid();
32 return Node.getNumParams() > 0;
40 "FunctionsThatShouldNotThrow",
"")),
41 RawIgnoredExceptions(Options.get(
"IgnoredExceptions",
"")) {
42 llvm::SmallVector<StringRef, 8> FunctionsThatShouldNotThrowVec,
44 StringRef(RawFunctionsThatShouldNotThrow)
45 .split(FunctionsThatShouldNotThrowVec,
",", -1,
false);
46 FunctionsThatShouldNotThrow.insert(FunctionsThatShouldNotThrowVec.begin(),
47 FunctionsThatShouldNotThrowVec.end());
49 llvm::StringSet<> IgnoredExceptions;
50 StringRef(RawIgnoredExceptions).split(IgnoredExceptionsVec,
",", -1,
false);
51 IgnoredExceptions.insert(IgnoredExceptionsVec.begin(),
52 IgnoredExceptionsVec.end());
59 RawFunctionsThatShouldNotThrow);
60 Options.
store(Opts,
"IgnoredExceptions", RawIgnoredExceptions);
68 allOf(anyOf(cxxDestructorDecl(),
69 cxxConstructorDecl(isMoveConstructor()),
70 cxxMethodDecl(isMoveAssignmentOperator()), isMain(),
71 allOf(hasAnyName(
"swap",
"iter_swap",
"iter_move"),
72 hasAtLeastOneParameter())),
73 unless(isExplicitThrow())),
74 isEnabled(FunctionsThatShouldNotThrow)))
80 const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>(
"thrower");
89 diag(MatchedDecl->getLocation(),
"an exception may be thrown in function "
90 "%0 which should not throw exceptions")
llvm::SmallString< 256U > Name
::clang::DynTypedNode Node
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.
Base class for all clang-tidy checks.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
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...
ExceptionEscapeCheck(StringRef Name, ClangTidyContext *Context)
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
State getBehaviour() const
void ignoreBadAlloc(bool ShallIgnore)
void ignoreExceptions(llvm::StringSet<> ExceptionNames)
@ Throwing
The function can definitely throw given an AST.
ExceptionInfo analyze(const FunctionDecl *Func)
AST_MATCHER_P(FunctionDecl, parameterCountGE, unsigned, N)
Matches functions that have at least the specified amount of parameters.
AST_MATCHER(clang::VarDecl, hasConstantDeclaration)
llvm::StringMap< ClangTidyValue > OptionMap