-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang-tidy] Fix bugprone-exception-escape not diagnosing throws in argument lists
#165955
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -563,16 +563,6 @@ ExceptionAnalyzer::throwsException(const Stmt *St, | |
| } | ||
| } | ||
| Results.merge(Uncaught); | ||
| } else if (const auto *Call = dyn_cast<CallExpr>(St)) { | ||
| if (const FunctionDecl *Func = Call->getDirectCallee()) { | ||
| ExceptionInfo Excs = | ||
| throwsException(Func, Caught, CallStack, Call->getBeginLoc()); | ||
| Results.merge(Excs); | ||
| } | ||
| } else if (const auto *Construct = dyn_cast<CXXConstructExpr>(St)) { | ||
| ExceptionInfo Excs = throwsException(Construct->getConstructor(), Caught, | ||
| CallStack, Construct->getBeginLoc()); | ||
| Results.merge(Excs); | ||
| } else if (const auto *DefaultInit = dyn_cast<CXXDefaultInitExpr>(St)) { | ||
| ExceptionInfo Excs = | ||
| throwsException(DefaultInit->getExpr(), Caught, CallStack); | ||
|
|
@@ -601,10 +591,25 @@ ExceptionAnalyzer::throwsException(const Stmt *St, | |
| Results.merge(Excs); | ||
| } | ||
| } else { | ||
| // Check whether any of this node's subexpressions throws. | ||
| for (const Stmt *Child : St->children()) { | ||
| ExceptionInfo Excs = throwsException(Child, Caught, CallStack); | ||
| Results.merge(Excs); | ||
| } | ||
|
|
||
| // If this node is a call to a function or constructor, also check | ||
| // whether the call itself throws. | ||
| if (const auto *Call = dyn_cast<CallExpr>(St)) { | ||
| if (const FunctionDecl *Func = Call->getDirectCallee()) { | ||
| ExceptionInfo Excs = | ||
| throwsException(Func, Caught, CallStack, Call->getBeginLoc()); | ||
| Results.merge(Excs); | ||
| } | ||
| } else if (const auto *Construct = dyn_cast<CXXConstructExpr>(St)) { | ||
|
Comment on lines
+602
to
+608
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking out loud, I think it will be more readable if instead of placing } else if (const auto *Call = dyn_cast<CallExpr>(St)) {
Results.merge(CheckChildren(St)); // New code!
if (const FunctionDecl *Func = Call->getDirectCallee()) {
ExceptionInfo Excs =
throwsException(Func, Caught, CallStack, Call->getBeginLoc());
Results.merge(Excs);
}
} else if (const auto *Construct = dyn_cast<CXXConstructExpr>(St)) {
Results.merge(CheckChildren(St)); // New code!
ExceptionInfo Excs = throwsException(Construct->getConstructor(), Caught,
CallStack, Construct->getBeginLoc());
Results.merge(Excs);
}I'd rather see this more straightforward solution instead of twisting order of branches, which seem to me more bugprone and harder to read, WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, I'd really like to see this big function separated in N smaller with each function corresponding to each type of node we process. |
||
| ExceptionInfo Excs = throwsException(Construct->getConstructor(), Caught, | ||
| CallStack, Construct->getBeginLoc()); | ||
| Results.merge(Excs); | ||
| } | ||
| } | ||
| return Results; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.