forked from OSchip/llvm-project
[clang-tidy] Simplify throw keyword missing check
Extend test to verify that it does not match in template instantiations. Differential Revision: https://reviews.llvm.org/D96132
This commit is contained in:
parent
6852a29a3b
commit
77056fe58e
|
@ -21,17 +21,16 @@ void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
|
|||
cxxConstructorDecl(hasAnyConstructorInitializer(anything()));
|
||||
|
||||
Finder->addMatcher(
|
||||
expr(anyOf(cxxFunctionalCastExpr(), cxxBindTemporaryExpr(),
|
||||
cxxTemporaryObjectExpr()),
|
||||
hasType(cxxRecordDecl(
|
||||
isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION")))),
|
||||
unless(anyOf(hasAncestor(stmt(
|
||||
anyOf(cxxThrowExpr(), callExpr(), returnStmt()))),
|
||||
hasAncestor(varDecl()),
|
||||
allOf(hasAncestor(CtorInitializerList),
|
||||
unless(hasAncestor(cxxCatchStmt()))))))
|
||||
cxxConstructExpr(
|
||||
hasType(cxxRecordDecl(
|
||||
isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION")))),
|
||||
unless(anyOf(hasAncestor(stmt(
|
||||
anyOf(cxxThrowExpr(), callExpr(), returnStmt()))),
|
||||
hasAncestor(varDecl()),
|
||||
allOf(hasAncestor(CtorInitializerList),
|
||||
unless(hasAncestor(cxxCatchStmt()))))))
|
||||
.bind("temporary-exception-not-thrown"),
|
||||
this);
|
||||
this);
|
||||
}
|
||||
|
||||
void ThrowKeywordMissingCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
|
|
|
@ -29,6 +29,9 @@ public:
|
|||
}
|
||||
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
|
||||
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
||||
llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
|
||||
return TK_IgnoreUnlessSpelledInSource;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace bugprone
|
||||
|
|
|
@ -94,8 +94,17 @@ void nameContainsExceptionThrownTest(int i) {
|
|||
template <class Exception>
|
||||
void f(int i, Exception excToBeThrown) {}
|
||||
|
||||
template <class SomeType>
|
||||
void templ(int i) {
|
||||
if (i > 0)
|
||||
SomeType();
|
||||
}
|
||||
|
||||
void funcCallWithTempExcTest() {
|
||||
f(5, RegularException());
|
||||
|
||||
templ<RegularException>(4);
|
||||
templ<RegularClass>(4);
|
||||
}
|
||||
|
||||
// Global variable initialization test.
|
||||
|
|
Loading…
Reference in New Issue