File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,8 @@ void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
20
20
hasType (cxxRecordDecl (anyOf (
21
21
matchesName (" [Ee]xception|EXCEPTION" ),
22
22
hasAnyBase (hasType (hasCanonicalType (recordType (hasDeclaration (
23
- cxxRecordDecl (matchesName (" [Ee]xception|EXCEPTION" )))))))))),
23
+ cxxRecordDecl (matchesName (" [Ee]xception|EXCEPTION" ))
24
+ .bind (" base" ))))))))),
24
25
unless (anyOf (
25
26
hasAncestor (
26
27
stmt (anyOf (cxxThrowExpr (), callExpr (), returnStmt ()))),
@@ -39,6 +40,11 @@ void ThrowKeywordMissingCheck::check(const MatchFinder::MatchResult &Result) {
39
40
diag (TemporaryExpr->getBeginLoc (), " suspicious exception object created but "
40
41
" not thrown; did you mean 'throw %0'?" )
41
42
<< TemporaryExpr->getType ().getBaseTypeIdentifier ()->getName ();
43
+
44
+ if (const auto *BaseDecl = Result.Nodes .getNodeAs <Decl>(" base" ))
45
+ diag (BaseDecl->getLocation (),
46
+ " object type inherits from base class declared here" ,
47
+ DiagnosticIDs::Note);
42
48
}
43
49
44
50
} // namespace clang::tidy::bugprone
Original file line number Diff line number Diff line change @@ -272,7 +272,8 @@ Changes in existing checks
272
272
273
273
- Improved :doc: `bugprone-throw-keyword-missing
274
274
<clang-tidy/checks/bugprone/throw-keyword-missing>` check by only considering
275
- the canonical types of base classes as written.
275
+ the canonical types of base classes as written and adding a note on the base
276
+ class that triggered the warning.
276
277
277
278
- Improved :doc: `bugprone-unchecked-optional-access
278
279
<clang-tidy/checks/bugprone/unchecked-optional-access>` check by supporting
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ typedef basic_string<char> string;
20
20
typedef basic_string<wchar_t > wstring;
21
21
22
22
// std::exception and std::runtime_error declaration.
23
+ // CHECK-MESSAGES-DAG: [[#EXCEPTION_LINE:@LINE + 1]]:8
23
24
struct exception {
24
25
exception ();
25
26
exception (const exception &other);
@@ -50,12 +51,13 @@ struct RegularException {
50
51
51
52
void stdExceptionNotTrownTest (int i) {
52
53
if (i < 0 )
53
- // CHECK-MESSAGES: :[[@LINE+1]]:5: warning: suspicious exception object created but not thrown; did you mean 'throw {{.*}}'? [bugprone-throw-keyword-missing]
54
+ // CHECK-MESSAGES-DAG : :[[@LINE+1]]:5: warning: suspicious exception object created but not thrown; did you mean 'throw {{.*}}'? [bugprone-throw-keyword-missing]
54
55
std::exception ();
55
56
56
57
if (i > 0 )
57
- // CHECK-MESSAGES: :[[@LINE+1]]:5: warning: suspicious exception
58
+ // CHECK-MESSAGES-DAG : :[[@LINE+1]]:5: warning: suspicious exception
58
59
std::runtime_error (" Unexpected argument" );
60
+ // CHECK-MESSAGES: note: object type inherits from base class declared here
59
61
}
60
62
61
63
void stdExceptionThrownTest (int i) {
@@ -181,6 +183,7 @@ class RegularError : public ERROR_BASE {};
181
183
void typedefTest () {
182
184
// CHECK-MESSAGES: :[[@LINE+1]]:3: warning: suspicious exception
183
185
RegularError ();
186
+ // CHECK-MESSAGES: :[[#EXCEPTION_LINE]]:8: note: object type inherits from base class declared here
184
187
}
185
188
186
189
struct ExceptionRAII {
You can’t perform that action at this time.
0 commit comments