Skip to content
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

[temp.arg.template] p4 Saying PP is an id-expression has a wrong assumption #5372

Open
xmh0511 opened this issue Mar 28, 2022 · 7 comments
Open

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Mar 28, 2022

The second bullet in [temp.arg.template] p4 says

If PP declares a template parameter pack, then AA is the pack expansion PP... ([temp.variadic]); otherwise, AA is the id-expression PP.

The id-expression implies that PP can only be a non-type template parameter since whose declarator-id is an id-expression. The name of the type template parameter is either typedef-name or template-name, as per [temp.param] p3

A type-parameter whose identifier does not follow an ellipsis defines its identifier to be a typedef-name (if declared without template) or template-name (if declared with template) in the scope of the template declaration.

Maybe, we change the last sentence to

otherwise, AA is the identifier naming PP.

is better?

@xmh0511 xmh0511 changed the title [temp.arg.template] p4 Saying PP is an id-expression is a wrong assumption [temp.arg.template] p4 Saying PP is an id-expression has a wrong assumption Mar 28, 2022
@jensmaurer
Copy link
Member

Even though id-expressions is introduced inside [expr], we use it in situations where it is not actually an expression. For example, for declarator-id in [dcl.decl.general].

I agree that id-expression should be moved outside of [expr], and only the parts relevent for [expr] should stay there (value category, result).

@xmh0511
Copy link
Contributor Author

xmh0511 commented Mar 29, 2022

For example, for declarator-id in [dcl.decl.general].

Yes, since the declarator-id is an id-expression in grammar, which is reasonable that name lookup can interpret the name as an id-expression that is able to appear in an expression when that name appears in an expression. That is why I said id-expression may limit the template parameter as a non-type template parameter because that parameter's declaration has a declarator-id that is an id-expression. However, any type template parameter is introduced by an identifier, the lookup rules apply to the name shouldn't interpret that name as an id-expression, as we discussed in #5345 (comment) and #5341 (comment)

Anyway, typedef-name and template-name are not comprised by the grammar of an id-expression.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Mar 30, 2022

For template argument corresponding to template template-parameter, we have [temp.arg.template] p1 that specifies that the template-argument is expressed as id-expression. So, it could be arguably correct that we say AA is an id-expression when PP is a template template-parameter

However, we do not have a similar special phrase that specifies the type template-argument is expressed as an id-expression. [temp.arg.type] p1 says such a template-argument shall be a type-id.

A template-argument for a template-parameter which is a type shall be a type-id.

type-id is not an id-expression and vice versa.


BTW, [temp.arg.template] p1 requires that the template-argument for template template-paramter shall be the name of a class template or an alias template. It is unclear whether a name introduced by a template template-parameter can be considered to be a name of a class template or of an alias template or not? We do not have a relevant phrase.

@jensmaurer
Copy link
Member

For the last point, I think we want [temp.param] p3 to say "... template-name that designates a template whose specializations are types".

@xmh0511
Copy link
Contributor Author

xmh0511 commented Mar 30, 2022

I think we want [temp.param] p3 to say "... template-name that designates a template whose specializations are types".

Is it [temp.arg.template] p1 instead of [temp.param] p3? I think [temp.arg.template] p1 might be changed to

A template-argument for a template template-parameter shall be a template-name that designates a template whose specializations are types, expressed as id-expression.


How about the point that a type-id(especially, typedef-name) is not an id-expression? I think it also should be fixed.

@jensmaurer
Copy link
Member

[temp.arg.template] is concerned with template arguments, i.e. the use of templates. [temp.param] is concerned with template parameters, i.e. the declaration and definition of templates. In order to properly syntax-check a template definition, I think we need to know that the identifier introduced via a template template parameter is actually (similar to) a class/alias template. Maybe we want to even say that those are alias templates.

I think [temp.arg.template] is fine as-is; this is just another place where id-expression is used with a non-expression meaning (which ought to be fixed, but not like this).

@xmh0511
Copy link
Contributor Author

xmh0511 commented Mar 30, 2022

@jensmaurer

a template template parameter is actually (similar to) a class/alias template. Maybe we want to even say that those are alias templates.

I also think so. So, there are two remaining issues, [temp.param] p3 might be fixed by:

  • A type-parameter whose identifier does not follow an ellipsis declares its identifier to be an alias template that is a template-name(if declared with template)

Another issue is we should give a special rule to specify the name of a type template parameter (declared without template) whose name becomes a typedef-name is interpreted as an id-expression whenever it is used as a template-argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants