问题
Given some class template:
template <typename> struct T {};
a type alias declaration that changes the meaning of the name T
like this is not allowed:
struct S {
using T = T<void>; // ill formed no diagnostic required
};
There is an explanation given here as to why this is the case, and it also suggests a fix:
struct S {
using T = ::T<void>; // ok
};
So my question is, how about an alias template as in this case?
struct S {
template <typename> using T = T<void>; // ok ?
};
Is this well formed? A type alias is a different kind of entity than an alias template, so I don't know if the reasoning from the linked answer applies.
For what it's worth, the diagnostic that gcc (helpfully) issues in the type alias example is not issued with the alias template example.
Here's the code to play with.
来源:https://stackoverflow.com/questions/63369264/is-a-nested-alias-template-that-redeclares-the-same-name-valid