[PATCH] D96132: [clang-tidy] Simplify throw keyword missing check
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 20 14:08:00 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG77056fe58e83: [clang-tidy] Simplify throw keyword missing check (authored by stephenkelly).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D96132/new/
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.325242.patch
Type: text/x-patch
Size: 2801 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210220/31299edb/attachment-0001.bin>
More information about the cfe-commits
mailing list