Skip to content

Commit 69fb9bc

Browse files
carlosgalvezpCarlos Gálvez
and
Carlos Gálvez
authored
Fix false positive in bugprone-throw-keyword-missing (#115302)
Fixes #115055 --------- Co-authored-by: Carlos Gálvez <[email protected]>
1 parent 230946f commit 69fb9bc

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ using namespace clang::ast_matchers;
1515
namespace clang::tidy::bugprone {
1616

1717
void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
18-
auto CtorInitializerList =
19-
cxxConstructorDecl(hasAnyConstructorInitializer(anything()));
20-
2118
Finder->addMatcher(
2219
cxxConstructExpr(
2320
hasType(cxxRecordDecl(
@@ -27,7 +24,7 @@ void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
2724
stmt(anyOf(cxxThrowExpr(), callExpr(), returnStmt()))),
2825
hasAncestor(decl(anyOf(varDecl(), fieldDecl()))),
2926
hasAncestor(expr(cxxNewExpr(hasAnyPlacementArg(anything())))),
30-
allOf(hasAncestor(CtorInitializerList),
27+
allOf(hasAncestor(cxxConstructorDecl()),
3128
unless(hasAncestor(cxxCatchStmt()))))))
3229
.bind("temporary-exception-not-thrown"),
3330
this);

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ Changes in existing checks
177177
usages of ``sizeof()``, ``alignof()``, and ``offsetof()`` when adding or
178178
subtracting from a pointer directly or when used to scale a numeric value.
179179

180+
- Improved :doc:`bugprone-throw-keyword-missing
181+
<clang-tidy/checks/bugprone/throw-keyword-missing>` by fixing a false positive
182+
when using non-static member initializers and a constructor.
183+
180184
- Improved :doc:`bugprone-unchecked-optional-access
181185
<clang-tidy/checks/bugprone/unchecked-optional-access>` to support
182186
`bsl::optional` and `bdlb::NullableValue` from

clang-tools-extra/test/clang-tidy/checkers/bugprone/throw-keyword-missing.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ CtorInitializerListTest::CtorInitializerListTest(float) try : exc(RegularExcepti
139139
RegularException();
140140
}
141141

142+
namespace GH115055 {
143+
class CtorInitializerListTest2 {
144+
public:
145+
CtorInitializerListTest2() {}
146+
private:
147+
RegularException exc{};
148+
};
149+
} // namespace GH115055
150+
142151
RegularException funcReturningExceptionTest(int i) {
143152
return RegularException();
144153
}

0 commit comments

Comments
 (0)