2

MSVC 19.28 rejects the following code with the error message: C2668 ambiguous call to overloaded function A::Foo. Is it a compiler bug? It compiles fine with gcc, clang and even msvc 19.10. It fails since MSVC 19.14, see here

#include <iostream>

class A {
public:
    template<typename T>
    void Foo(int = {}) {
        std::cout << "Hello World";
    }

    template<typename... T, typename... Args>
    void Foo(Args&&... args) {

    }
};

int main()
{
    A a;
    a.Foo<int>();
}
Bernd
  • 2,113
  • 8
  • 22

1 Answers1

1

For the call Foo<int>() the compiler can deduce Foo<int>() for the first template, and Foo<int>(void) for the second.

From temp.deduct.partial#11:

... if G has a trailing function parameter pack for which F does not have a corresponding parameter, and if F does not have a trailing function parameter pack, then F is more specialized than G.

This is a tie breaker, and the first template is selected.

Not being able to resolve the ambiguity appears to be a MSVC bug.

cigien
  • 57,834
  • 11
  • 73
  • 112
  • "for which F does not have a corresponding parameter" - but F does have a corresponding parameter, the anonymous `int` parameter? – ecatmur Mar 13 '22 at 19:25