[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:
Stephen Kelly 2020-12-28 01:54:04 +00:00
parent 6852a29a3b
commit 77056fe58e
3 changed files with 21 additions and 10 deletions

View file

@ -21,8 +21,7 @@ void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
cxxConstructorDecl(hasAnyConstructorInitializer(anything()));
Finder->addMatcher(
expr(anyOf(cxxFunctionalCastExpr(), cxxBindTemporaryExpr(),
cxxTemporaryObjectExpr()),
cxxConstructExpr(
hasType(cxxRecordDecl(
isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION")))),
unless(anyOf(hasAncestor(stmt(

View file

@ -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

View file

@ -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.