VS2017 template specialization error cannot convert from 'Class *(__cdecl *)(Args...)' to 'Class *(__cdecl *)(Args...)'

Viewed 632

This is a simplistic version of a codebase that I am migrating to VS2017. The following code compiles in VS2013 and Intel C++ compiler 2017 update 4 but not in VS2013.

#include  <type_traits>

template<typename F, F f>
struct S1
{};
template<typename F, F f>
struct S2
{};

template<typename F, F f>
using BaseType = typename std::conditional<std::is_member_function_pointer<F>::value, S1<F, f>, S2<F, f>>::type;

template<typename Class, typename... Args>
Class * call_constructor(Args... args)
{
    return new Class(args...);
}

template<class Class, typename... Args>
struct Constructor : BaseType<Class *(*)(Args...), call_constructor<Class, Args...>>
{
    using ReturnType = Class *;
};

int main() {}

I am getting an error on the definition of Constructor class:

main.cpp(20): error C2440: 'specialization': cannot convert from 'Class *(__cdecl *)(Args...)' to 'Class *(__cdecl *)(Args...)' note: None of the functions with this name in scope match the target type note: see reference to class template instantiation 'Constructor' being compiled

If I inherit Constructor from directly S1 or S2 the error goes away. So I think the problem is about the std::conditional definitions.

Any ideas? Thanks.

1 Answers
Related