ERROR: partial ordering for explicit instantiation of 'f' is ambiguous when two template function only differ in template argument number

Viewed 182

The following code cannot compile with clang, but ok with msvc and gcc. WHY?

If I define f<X, int, int> function as template <typename X, int A, int B> void f (X x, position<A>) {}, the code could compile.

Seems clang will look at the function parameter first and then the template argument?

template<int d>
struct position {

};

template <typename X, int A>
void f (X x, position<A>) {}

template <typename X, int A, int B>
void f (X x, position<B>) {}

// This one would work
// template <typename X, int A, int B>
// void f (X x, position<A>) {}


template void f<int, 2>(int x, position<2>);
template void f<int, 2, 1>(int x, position<1>);

int main()
{
    f<int, 2, 1>(1, position<1>());
}

code link: https://gcc.godbolt.org/z/PWrbns

0 Answers
Related