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,
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);
56 functionDecl(anyOf(isNoThrow(), cxxDestructorDecl(),
57 cxxConstructorDecl(isMoveConstructor()),
58 cxxMethodDecl(isMoveAssignmentOperator()),
59 hasName(
"main"), hasName(
"swap"),
60 isEnabled(FunctionsThatShouldNotThrow)))
66 const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>(
"thrower");
75 diag(MatchedDecl->getLocation(),
76 "an exception may be thrown in function %0 "
78 "which should not throw exceptions")