Skip to content

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

Merged
merged 4 commits into from
Oct 26, 2018

Conversation

jbj
Copy link
Contributor

@jbj jbj commented Oct 24, 2018

@jbj jbj added the C++ label Oct 24, 2018
// 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))
Copy link
Contributor

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 ReturnStmts, one which returns *this and the other a compiler generated return that's unreachable?

Copy link
Contributor Author

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.

jbj added 2 commits October 25, 2018 09:42
This test shows that the previous fix did not solve the problem where a
bad return statement exists but is unreachable.
Copy link
Contributor

@geoffw0 geoffw0 left a 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.

@geoffw0 geoffw0 merged commit fa55e31 into github:master Oct 26, 2018
jbj added a commit to jbj/ql that referenced this pull request Nov 6, 2018
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.
aibaars added a commit that referenced this pull request Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants