1

I am trying to wrap a call to a template member function of a template class with a free function, and I do not understand why the snippet of code below compiles with MSVC but is rejected by gcc and 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

This code fails to compile with g++, with the error message error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator<'. Clang similarly refuses to compile this, complaining error: missing 'template' keyword prior to dependent template name 'f'.

MSVC happily compiles the full example with no errors or warnings.

Is this code valid C++ or are gcc and clang correct to reject it?

0 Answers0