-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Analyzer fails initializing_formal_final_test #34369
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
Comments
The spec excerpt
specifies the current scope for the initializer list of a constructor with initializing formal parameters. Any expressions in the initializer list are resolved according to the current scope, and there is no need to mention at each point where an expression is considered which scope is current. That approach is used everywhere; e.g., when considering the meaning of an expression in the body of a function we're implicitly using the fact that its current scope (unless nested in something like function literal etc.) is the body scope of the function. So
This one is about initialization of instance variables whose declaration includes an initializing expression, so that's completely separate from the semantics of initializer lists. In that case the current scope is the instance scope of the class, and there is a special rule which makes it a compile-time error to reference
So you could say that the current scope for You could claim that we should be more forgiving in the body of a function literal which is statically guaranteed to not run before initialization list evaluation has completed (which makes it similar to expressions in the constructor body, or indeed the body of any instance member), which would mean that it wouldn't hurt to allow such a function literal body to access It's possible that we can make the specification of scoping simpler and more readable, but I think the current approach is at least reasonable: Scopes are specified for each syntactic location where a term occurs for which one or more names may be looked up (e.g., all locations where an expression can occur), and the semantics of all such terms will never talk about scoping unless they introduce a new scope, they always just rely on looking up names in the 'current' scope. For lookups, it's enough to know that we have a scope which is current for a certain location, it introduces a certain set of bindings (statically, and the dynamic semantics just needs to make it work as if we had all those scopes and looked up names lexically), and it has another specific scope as its enclosing scope. We mention each situation where a new scope is introduced, otherwise we just use the rule that when t' is a subterm of t and t doesn't introduce a new scope, t' has the same current scope as t. @MichaelRFairhurst, does that make it more meaningful? |
@eernstg Thanks, that does help! @leafpetersen you're right, the CFE does pass this. Not sure what test I had run that gave me the impression otherwise. Changing this to an analyzer issue. |
Analyzer now reports an error. |
I'm having difficulty pinning down whether this is still latest spec behavior, and what the rationale for it was.
Given that neither the analyzer nor CFE pass this test, it seems like maybe it should be removed?edit: the analyzer is incorrect here, and this test is valid. Keeping issue open for us to make a fix.
From the spec:
There are no other references to "formal parameter initializer scope," and the section on initializer lists doesn't reference scopes at all, but rather magically talks about:
where some scope of evaluation is assumed but not expressed. Similarly, the "formalParameters" section doesn't mention anything either.
I get the feeling, best I can make of this, that the test is correct. However, I'm not confident there, and I'm suspicious of the value that this complexity in the spec adds.
The text was updated successfully, but these errors were encountered: