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
The grammar template-name component has a narrow definition #5345
Comments
As discussed in the mentioned issue. If we prepare to restrict certain language constructs by using grammar, identifier is too flexible. Since lookup only concerns name and the entity introduced by the declaration. Even if we augment the definition of template-name, it is still not sufficient. Because of the identifier, we still need to draft the wording as that: if..., the name shall be introduced by a template declaration. In order to make the restriction that is in terms of the grammar to work, we might have a formal rule that means as the following:
T::X * i; // #1 Whether the language construct at |
We need something like [class.pre] for templates. |
In translation phase 7, all preprocessing identifier tokens are just converted to an identifier token as specified in [lex.token]. I think we should also need a rule to explicitly state that the identifier will be reinterpreted to a high-level grammar(after lookup?), which can be convenient to limit the context where the identifier can be used. I think it is exactly the meaning of defining high-level grammar. We can say an unqualified-id can be an identifier but it is not the other way around, unqualified-id, therefore, is more special than an identifier. When an identifier is identified to be an unqualified-id, the latter can narrow the context where the identifier can be used. struct X{};
int main(){
X * i;
} In translation phase 7, The quo status is, we just cannot clearly interpret why the identifier |
I think we've this part covered okay-ish: [expr.prim.id.unqual] p1 "An identifier is only an id-expression if it has been suitably declared (Clause 9) or if it appears as part of a declarator-id (9.3). An identifier that names a coroutine parameter refers to the copy of the parameter (9.5.4)." |
I would say this is a bit unclear. What does the "suitably declared" exactly mean? We seem to have not given the concrete specification. From certain perspectives, that means what declaration is found by lookup for that name, and therefore resulting in how the identifier will be reinterpreted or could say what high-level grammar identity the underlying identifier will be promoted to. That results will ultimately determine the context in which the use of the identifier is valid. If possible, we should explicitly specify what the name will become when a declaration introduces it. Similar to [class.pre] have done.
And we might make a rule and add it to [basic.lookup], the rule might mean
Then we will clearly know the reason why we categorize the identifiers into various high-level grammar stuff. |
X
is a class-name introduced by the declaration at#1
. However, a simple-template-id is defined as:template-name
cannot be a class-name. Unlike other grammar definitions, they include as many as possible grammar components that can be used to form that grammar. Specifically, such as the qualified-id:where the grammar nested-name-specifier is defined as:
where the grammar type-name can be broken up into that:
That means, the grammar in the following example all can be covered
X::
andA::
are nested-name-specifiers where the first is class-name and the second is namespace-name, even though they ultimately are identifiers. Conversely, the template-name in a simple-template-id just includes an identifier. That is, it greatly limits what the components are. Although, [temp.names.note] p1 implies that a name that is an identifier can be reinterpreted as a template-name if possible. However, it is not a formal rule. The quo status is, a component can only be a template-name when we have explicitly specified it is a template-name. Such as [temp.alias] p1The text was updated successfully, but these errors were encountered: