Skip to content

Fix false positive in bugprone-throw-keyword-missing #115302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ using namespace clang::ast_matchers;
namespace clang::tidy::bugprone {

void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
auto CtorInitializerList =
cxxConstructorDecl(hasAnyConstructorInitializer(anything()));

Finder->addMatcher(
cxxConstructExpr(
hasType(cxxRecordDecl(
Expand All @@ -27,7 +24,7 @@ void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
stmt(anyOf(cxxThrowExpr(), callExpr(), returnStmt()))),
hasAncestor(decl(anyOf(varDecl(), fieldDecl()))),
hasAncestor(expr(cxxNewExpr(hasAnyPlacementArg(anything())))),
allOf(hasAncestor(CtorInitializerList),
allOf(hasAncestor(cxxConstructorDecl()),
unless(hasAncestor(cxxCatchStmt()))))))
.bind("temporary-exception-not-thrown"),
this);
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ Changes in existing checks
usages of ``sizeof()``, ``alignof()``, and ``offsetof()`` when adding or
subtracting from a pointer directly or when used to scale a numeric value.

- Improved :doc:`bugprone-throw-keyword-missing
<clang-tidy/checks/bugprone/throw-keyword-missing>` by fixing a false positive
when using non-static member initializers and a constructor.

- Improved :doc:`bugprone-unchecked-optional-access
<clang-tidy/checks/bugprone/unchecked-optional-access>` to support
`bsl::optional` and `bdlb::NullableValue` from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ CtorInitializerListTest::CtorInitializerListTest(float) try : exc(RegularExcepti
RegularException();
}

namespace GH115055 {
class CtorInitializerListTest2 {
public:
CtorInitializerListTest2() {}
private:
RegularException exc{};
};
} // namespace GH115055

RegularException funcReturningExceptionTest(int i) {
return RegularException();
}
Expand Down
Loading