-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C++: Add missing parent scope cases #17776
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
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
| 0 | file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | __va_list_tag | | ||
| 0 | file://:0:0:0:0 | (global namespace) | parents.cpp:2:11:2:13 | foo | | ||
| 0 | file://:0:0:0:0 | (global namespace) | parents.cpp:18:3:18:3 | var | | ||
| 0 | file://:0:0:0:0 | (global namespace) | parents.cpp:18:7:18:7 | var | | ||
| 0 | file://:0:0:0:0 | (global namespace) | parents.cpp:20:5:20:5 | g | | ||
| 1 | file://:0:0:0:0 | __va_list_tag | file://:0:0:0:0 | fp_offset | | ||
| 1 | file://:0:0:0:0 | __va_list_tag | file://:0:0:0:0 | gp_offset | | ||
| 1 | file://:0:0:0:0 | __va_list_tag | file://:0:0:0:0 | operator= | | ||
|
@@ -14,7 +17,11 @@ | |
| 1 | parents.cpp:4:10:4:10 | f | parents.cpp:4:19:13:5 | { ... } | | ||
| 1 | parents.cpp:4:19:13:5 | { ... } | parents.cpp:5:11:5:11 | j | | ||
| 1 | parents.cpp:4:19:13:5 | { ... } | parents.cpp:6:11:10:7 | { ... } | | ||
| 1 | parents.cpp:4:19:13:5 | { ... } | parents.cpp:11:18:11:18 | e | | ||
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. It feels like the parent of 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. Yeah, agreed. I struggled a bit with that one initially. What I do now seems to be most in line with all the other cases that are there, and what we want when looking for shadowing. |
||
| 1 | parents.cpp:4:19:13:5 | { ... } | parents.cpp:11:21:12:7 | { ... } | | ||
| 1 | parents.cpp:6:11:10:7 | { ... } | parents.cpp:7:9:9:9 | for(...;...;...) ... | | ||
| 1 | parents.cpp:6:11:10:7 | { ... } | parents.cpp:7:33:9:9 | { ... } | | ||
| 1 | parents.cpp:7:33:9:9 | { ... } | parents.cpp:8:15:8:15 | k | | ||
| 1 | parents.cpp:18:7:18:7 | var | parents.cpp:17:19:17:19 | T | | ||
| 1 | parents.cpp:20:5:20:5 | g | parents.cpp:20:9:24:1 | { ... } | | ||
| 1 | parents.cpp:20:9:24:1 | { ... } | parents.cpp:21:16:21:16 | l | |
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.
@jketema Could you explain the rationale behind making the parent scope of a catch block parameter the parent scope of the
TryStmt
? Surely it should be the catch block itself?This is what is breaking the Coding Standards
IdentifierHiding.ql
query. That query tries to find pairs of identifiers where the second hides the first. By considering to the parameter of a catch block to have a parent scope of the parent of theTryStmt
we erroneously report cases like this: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.
This seemed to be most consistent with the other cases here. For example, for functions the parent scope is the whole function, and not the statement block that forms the body of the function. The latter would correspond with the catch block in the case of a try-catch.
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.
Just checking, but I presume you mean "for parameters the parent scope is the whole function"?
If so, I think it would be reasonable on that basis to report the
Handler
of theCatchBlock
as the parent scope of the parameter. But reporting the parent of theTryStmt
as the "scope" erroneously puts it in the same scope as other variables declared outside theTryStmt
. Given the main purpose of this predicate is to support identifier hiding queries, this seems like it's not ideal.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.
The problem is that
Handler
is not exposed anywhere else in the QL API, and it's only really visible in the AST, so that's far from ideal either.