clang fails to parse type alias in explicit calling of template member function with `->template `
Please consider the following code:
template <typename T>
struct A {
int a() {
return 42;
}
};
template <typename T>
struct B {
using MUT_1 = A<T>;
int b(MUT_1 *p) {
return p->template MUT_1::a();
}
};
int main() {
A<int> a;
B<int> b;
return b.b(&a);
}
Clang rejects it by complaining that:
<source>:13:28: error: a template argument list is expected after a name prefixed by the template keyword [-Wmissing-template-arg-list-after-template-kw]
13 | return p->template MUT_1::a();
| ^
<source>:13:33: error: expected ';' after return statement
13 | return p->template MUT_1::a();
| ^
| ;
<source>:13:28: error: no member named 'MUT_1' in 'A<int>'
13 | return p->template MUT_1::a();
| ~ ^
<source>:20:14: note: in instantiation of member function 'B<int>::b' requested here
20 | return b.b(&a);
It seems the compiler does not correctly understand the type alias expression of using MUT_1 = A<T>;. Directly using A<T> without setting up an alias won't trigger any error. Additionally, GCC also accepts this code.
Please check https://godbolt.org/z/oYre1GEh3
@llvm/issue-subscribers-clang-frontend
Author: None (Rush10233)
template <typename T>
struct A {
int a() {
return 42;
}
};
template <typename T>
struct B {
using MUT_1 = A<T>;
int b(MUT_1 *p) {
return p->template MUT_1::a();
}
};
int main() {
A<int> a;
B<int> b;
return b.b(&a);
}
Clang rejects it by complaining that:
<source>:13:28: error: a template argument list is expected after a name prefixed by the template keyword [-Wmissing-template-arg-list-after-template-kw]
13 | return p->template MUT_1::a();
| ^
<source>:13:33: error: expected ';' after return statement
13 | return p->template MUT_1::a();
| ^
| ;
<source>:13:28: error: no member named 'MUT_1' in 'A<int>'
13 | return p->template MUT_1::a();
| ~ ^
<source>:20:14: note: in instantiation of member function 'B<int>::b' requested here
20 | return b.b(&a);
It seems the compiler does not correctly understand the type alias expression of using MUT_1 = A<T>;. Directly using A<T> without setting up an alias won't trigger any error. Additionally, GCC also accepts this code.
Please check https://godbolt.org/z/oYre1GEh3
clang is correct here see: https://github.com/llvm/llvm-project/issues/94194
Actually simply removing template makes this work: https://godbolt.org/z/KffbhcT11
Please reopen if I am missing something.