-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C++: Fix "Overloaded assignment does not return 'this'" for non-returning functions #362
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
Conversation
This rule should not apply to functions that never return.
// If a function does not have a reachable `ReturnStmt` then either its body | ||
// was not in the snapshot or it was established by the extractor or the CFG | ||
// pruning that the function never returns. | ||
and exists(ReturnStmt ret | ret.getEnclosingFunction() = op and reachable(ret)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to put the reachable
check in returnsDereferenceThis
?
As it stands, I suspect it will do the wrong thing if there are two ReturnStmt
s, one which returns *this
and the other a compiler generated return that's unreachable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, the check should be in the predicates where we quantify over ReturnStmt
. I can't see a problem with the example you mention, but I added tests to show three more FPs and then a commit to fix them. Performance looks good: the slowest predicate in the query took 0.5 seconds on LibreOffice.
This test shows that the previous fix did not solve the problem where a bad return statement exists but is unreachable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes, LGTM.
I removed this condition in github#362, thinking it was covered by the new conditions on return statements, but it turns out it wasn't in at least the following cases. 1. Assignment operators that are deleted or marked private in order to make them inaccessible. 2. Templates whose body was not extracted. While some of these results are technically valid, they are not nearly as interesting as the results that this query was designed to produce.
Reported at https://discuss.lgtm.com/t/multiple-c-false-positives/1451/1. This is quite similar to #354.