Knowing Where and why do we have to put the template
and typename
keywords, I was surprised to learn that MSVC accepts the following code:
struct foo {
using bar = int;
};
template <typename T>
void quux() {
T::template bar b;
}
int main() {
quux<foo>();
}
From my understanding, the usage of T::template bar b;
is incorrect. The correct way to declare b
would be to use typename
, like so: typename T::bar b;
(instead of T::template bar b;
). template
would imply that bar
is a, well, a template, which is not the case.
Is it a bug in MSVC resulting in it accepting incorrect code, or is it permitted by the standard and simply both Clang and GCC don't implement it that way (thus requiring the proper usage of typename
here)?