cplusplus / CWG

Core Working Group
23 stars 7 forks source link

[module.context] p3 What does "the template" refer to? #406

Open xmh0511 opened 1 year ago

xmh0511 commented 1 year ago

Full name of submitter (unless configured in github; will be published with the issue): Jim X

The original issue is https://github.com/cplusplus/draft/issues/4949

[module.context] p3 says:

During the implicit instantiation of a template whose point of instantiation is specified as that of an enclosing specialization ([temp.point]), the instantiation context is the union of the instantiation context of the enclosing specialization and, if the template is defined in a module interface unit of a module M and the point of instantiation is not in a module interface unit of M, the point at the end of the declaration-seq of the primary module interface unit of M (prior to the private-module-fragment, if any).

What does "the template" refer to? According to the grammar, it may refer to the prior appearance of "a template", however, as specified by the below example

the point at the end of translation unit #2, and

"the template" should also intend to mean the enclosing template. The definite article the may mislead here. Another issue, the third interpretation is the below example

the point of the call to f(0),

the point of the call to g(0),

We say

During the instantiation of any other template specialization, the instantiation context comprises the point of instantiation of the template.

During the implicit instantiation of a template whose point of instantiation is specified as that of an enclosing specialization ([temp.point]), the instantiation context is the union of the instantiation context of the enclosing specialization

The point of instantiation of the enclosing template f and g are defined by [temp.point] p1, anyhow, they are not the call sites.

Suggested Resolution

Change [module.context] p3 to

During the implicit instantiation of a template whose point of instantiation is specified as that of an enclosing specialization ([temp.point]), the instantiation context is the union of the instantiation context of the enclosing specialization and, if the template or the template of the enclosing specialization is defined in a module interface unit of a module M and the point of instantiation is not in a module interface unit of M, the point at the end of the declaration-seq of the primary module interface unit of M (prior to the private-module-fragment, if any) for each such template.

Change the third interpretation in the example to

the instantiation context of the specialization f<int>

the instantiation context of the specialization g<int>

frederick-vs-ja commented 1 year ago

Given [module.context] p3 says:

the instantiation context is the union of the instantiation context of the enclosing specialization

I think it's sufficiently clear that [module.context] p3 needs to be recursively interpreted, so there can already be more than one "the template" in the recursive interpretation.

xmh0511 commented 1 year ago

there can already be more than one "the template" in the recursive interpretation.

This should be the intent, however, in that whole sentence, "the template" may not convey that meaning clearly. In other words, you cannot determine whether "the template" refer to the priorly appeared "a template" or refer to more than one "template" that would be used in this context. Furthermore, "the template" appears after "a template" that is first appeared, if there is no more interpretation, "the template" commonly refers to "a template".