[PATCH] D43120: [clang-tidy] New checker for exceptions that are created but not thrown
Whisperity via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 9 05:29:39 PST 2018
whisperity requested changes to this revision.
whisperity added inline comments.
This revision now requires changes to proceed.
================
Comment at: clang-tidy/misc/ThrowKeywordMissingCheck.cpp:21
+void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
+ // This is a C++ only checker.
+ if (!getLangOpts().CPlusPlus)
----------------
Superfluous comment, this can be removed.
================
Comment at: clang-tidy/misc/ThrowKeywordMissingCheck.cpp:32
+ hasType(cxxRecordDecl(
+ isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION")))),
+ unless(anyOf(hasAncestor(stmt(
----------------
`matchesName` says
> Does not match typedefs of an underlying type with the given name.
Does your check find the following case?
```
typedef std::exception ERROR_BASE;
class my_error : public ERROR_BASE {
/* Usual yadda. */
};
int main() {
my_error();
}
```
================
Comment at: clang-tidy/misc/ThrowKeywordMissingCheck.cpp:46
+ Result.Nodes.getNodeAs<Expr>("temporary-exception-not-thrown");
+ diag(TemporaryExpr->getLocStart(), "exception created but is not thrown");
+}
----------------
Either use passive for both subsentences or don't use passive at all. Maybe one of the following could be a better wording:
> exception instantied and not thrown
> exception is constructed but is not thrown
> exception construction without a throw statement
================
Comment at: test/clang-tidy/misc-throw-keyword-missing.cpp:23
+// std::exception and std::runtime_error declaration
+struct exception{
+ exception();
----------------
Please format the code. Why isn't there a space before `{`?
================
Comment at: test/clang-tidy/misc-throw-keyword-missing.cpp:29
+
+struct runtime_error : public exception{
+ explicit runtime_error( const std::string& what_arg );
----------------
Format here too.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D43120
More information about the cfe-commits
mailing list