summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/cert/StaticObjectExceptionCheck.cpp
diff options
context:
space:
mode:
authorMalcolm Parsons <malcolm.parsons@gmail.com>2016-10-31 22:47:04 +0000
committerMalcolm Parsons <malcolm.parsons@gmail.com>2016-10-31 22:47:04 +0000
commit2792dccb36db377e0669dedcbca37ef53bde9669 (patch)
treec86407780b3122d993ed95045b273b90d6d20a4f /clang-tools-extra/clang-tidy/cert/StaticObjectExceptionCheck.cpp
parent1bd9fc7098eb290fdf1d142d8bef86fe05a965ef (diff)
downloadbcm5719-llvm-2792dccb36db377e0669dedcbca37ef53bde9669.tar.gz
bcm5719-llvm-2792dccb36db377e0669dedcbca37ef53bde9669.zip
[clang-tidy] Update cert-err58-cpp to match its new generalised form.
Summary: Aaron modified cert-err58-cpp to include all exceptions thrown before main() Update the check to match. Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25925 llvm-svn: 285653
Diffstat (limited to 'clang-tools-extra/clang-tidy/cert/StaticObjectExceptionCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/cert/StaticObjectExceptionCheck.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/clang-tools-extra/clang-tidy/cert/StaticObjectExceptionCheck.cpp b/clang-tools-extra/clang-tidy/cert/StaticObjectExceptionCheck.cpp
index 48ac59d74f7..a5d85277f2b 100644
--- a/clang-tools-extra/clang-tidy/cert/StaticObjectExceptionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cert/StaticObjectExceptionCheck.cpp
@@ -22,27 +22,37 @@ void StaticObjectExceptionCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
return;
- // Match any static or thread_local variable declaration that is initialized
- // with a constructor that can throw.
+ // Match any static or thread_local variable declaration that has an
+ // initializer that can throw.
Finder->addMatcher(
varDecl(anyOf(hasThreadStorageDuration(), hasStaticStorageDuration()),
unless(hasAncestor(functionDecl())),
- hasInitializer(ignoringImplicit(cxxConstructExpr(hasDeclaration(
- cxxConstructorDecl(unless(isNoThrow())).bind("ctor"))))))
+ anyOf(hasDescendant(cxxConstructExpr(hasDeclaration(
+ cxxConstructorDecl(unless(isNoThrow())).bind("func")))),
+ hasDescendant(cxxNewExpr(hasDeclaration(
+ functionDecl(unless(isNoThrow())).bind("func")))),
+ hasDescendant(callExpr(hasDeclaration(
+ functionDecl(unless(isNoThrow())).bind("func"))))))
.bind("var"),
this);
}
void StaticObjectExceptionCheck::check(const MatchFinder::MatchResult &Result) {
const auto *VD = Result.Nodes.getNodeAs<VarDecl>("var");
- const auto *Ctor = Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor");
+ const auto *Func = Result.Nodes.getNodeAs<FunctionDecl>("func");
diag(VD->getLocation(),
- "construction of %0 with %select{static|thread_local}1 storage "
+ "initialization of %0 with %select{static|thread_local}1 storage "
"duration may throw an exception that cannot be caught")
<< VD << (VD->getStorageDuration() == SD_Static ? 0 : 1);
- diag(Ctor->getLocation(), "possibly throwing constructor declared here",
- DiagnosticIDs::Note);
+
+ SourceLocation FuncLocation = Func->getLocation();
+ if(FuncLocation.isValid()) {
+ diag(FuncLocation,
+ "possibly throwing %select{constructor|function}0 declared here",
+ DiagnosticIDs::Note)
+ << (isa<CXXConstructorDecl>(Func) ? 0 : 1);
+ }
}
} // namespace cert
OpenPOWER on IntegriCloud