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.general] p2 template argument list of template-head seems to have a more restriction #4845

Open
xmh0511 opened this issue Aug 28, 2021 · 4 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Aug 28, 2021

The template argument list of a template-head is a template argument list in which the nth template argument has the value of the nth template parameter of the template-head. If the nth template parameter is a template parameter pack ([temp.variadic]), the nth template argument is a pack expansion whose pattern is the name of the template parameter pack.

Consider thie example

template<int I>
struct A{
    struct B;
};

template<int I>
struct A<I+0>::B{};  

The definition for class member B is rejected by most implementations. In this case, the nested-name-specifier is governed by [expr.prim.id.qual] p3

If A is the template argument list ([temp.arg]) of the corresponding template-head H ([temp.mem]), N nominates the primary template of T; H shall be equivalent to the template-head of T ([temp.over.link]).

Since I+0 can arguably be the value of the template parameter I, it should be the template argument list of the template-head. I don't know does it say has the value of the nth template parameter intends to give the possibility to the above example? However, for the parameter pack, it uses the name. From the practice, we should also use the name for the common template parameter too. It may be that

The template argument list of a template-head is a template argument list in which the nth template argument is the name(i.e. identifier) of the nth template parameter of the template-head.

@jensmaurer
Copy link
Member

I think "value of" allows typedefs, but "I" and "I+0" are not equivalent (although functionally equivalent), so I wouldn't expect "I+0" to work.

@opensdh, the wording here was introduced by your paper, I believe. Any thoughts here?

@xmh0511
Copy link
Contributor Author

xmh0511 commented Aug 30, 2021

The type template parameter that is not a pack or pack expansion is itself a typedef-name. Except that, I cannot figure out we can declare a typedef declaration in a declaration. If functionally equivalent is not considered here, why not we directly say it shall be the name of the corresponding parameter.

@opensdh
Copy link
Contributor

opensdh commented Aug 30, 2021

My assumption is that [temp.arg.general]/2 means "has the value of" to just be "is". If not that, the equivalence invoked in [expr.prim.id.qual]/3.2 is surely the right interpretation, which would reject I+0. (My intuition is really that the strict current-instantiation rules from [temp.dep.type] would apply here, but that doesn't really work in an out-of-class declaration when we don't know what template to search yet.)

@opensdh, the wording here was introduced by your paper, I believe. Any thoughts here?

That wording was merely moved by P1787R6 from [temp.dep.type]/2, where it dated back to C++11.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Aug 31, 2021

"has the value of" to just be "is"

Even if it were that, IMHO, the value of I+0 is the value of I. Since the proposition I = I+0, if I ∈ R, this proposition is always true. Moreover, for template type-parameter, even though we obey [temp.dep.type#2], std::remove_reference_t<decltype(std::declval<T>())> is not permitted in the nested-name-specifier of a member declaration outside its enclosing class template definition.

Let alone it seems there is no way to declare a variable in such context to make it equal to the template parameter. Hence, why not directly say the template argument shall be the identifier introduced by the template parameter declaration.

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

3 participants