[PATCH] D96132: [clang-tidy] Simplify throw keyword missing check
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 5 06:16:29 PST 2021
steveire created this revision.
steveire added reviewers: aaron.ballman, njames93.
Herald added subscribers: nullptr.cpp, xazax.hun.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D96132
Files:
clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
@@ -94,8 +94,17 @@
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.
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
@@ -29,6 +29,9 @@
}
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
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -21,17 +21,16 @@
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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96132.321739.patch
Type: text/x-patch
Size: 2801 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210205/b1dee1a7/attachment-0001.bin>
More information about the cfe-commits
mailing list