jeudi 26 octobre 2017

"Ambiguous call to overloaded function" with enum classes in MSVC compilers

I was trying to do template specialization with values, one incarnation being bool, while the other being enum class. I was fighting with the compiler for a day, but did not manage to overcome the "Ambiguous call to overloaded function" error. That code is ugly and rather long, but here is a simple test case:

#include <iostream>

enum class Foo { Bar };
enum class Waldo { Fred };

template<Foo ARG, typename... _Types>
inline bool DOIT( _Types&&... _Args )
{
    return true;
}

template<Waldo ARG, typename... _Types>
inline bool DOIT( _Types&&... _Args )
{
    return false;
}

int main()
{
    std::cout << DOIT<Foo::Bar>() << std::endl;
    std::cout << DOIT<Waldo::Fred>() << std::endl;
    return 0;
}

Both clang 3.8 and gcc 4.8.3 compiles this without a hitch, with the standard being set to c++11, but MSVC keeps firing me the C2668 error message.

AFAIK one reason for enum class was to avoid implicit conversion, but don't know for sure. Is this a compiler error, or some deficiency in the standard?

Aucun commentaire:

Enregistrer un commentaire