我试图用自由函数包装对模板类的模板成员函数的调用,但我不明白为什么下面的代码片段可以用MSVC编译,但被gcc和clang拒绝。
template <int N>
struct S {
template <int I>
void f();
};
template <int N, int I>
void call(S<N>& s) {
s.f<I>(); // g++-9.1 and clang++-8.0 complain here
}
template void call<4, 1>(S<4>&); // The exact numbers are unimportant
此代码无法使用g ++编译,并显示错误消息error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator<'
。
Clang同样拒绝编译它,抱怨error: missing 'template' keyword prior to dependent template name 'f'
。
MSVC可以愉快地编译完整的示例,而不会出现错误或警告。
此代码是有效的C ++,还是gcc和clang正确拒绝它?