MSVC: implicit template creation, although template constructor is not used

I am trying to compile Flusspferd on Windows using MSVC, but it fails due to a problem creating the template. For convenience of explanation, I rewrote the problem in simpler terms:

#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_convertible.hpp>

class UndefinedType;

class A
{

};

class TestClass {

public:

    TestClass(A* a)
    {

    }

    template<typename OtherType>
    TestClass(OtherType t, typename boost::disable_if<typename boost::is_convertible<OtherType, UndefinedType>::type>::type * = 0)
    {

    }
};

The problem is that TestClass contains a template constructor that uses boost :: is_convertible with the UndefinedType redirected class. is_convertible only works for full types, which means that this constructor should only be used when UndefinedType has been defined, otherwise the template instance will not work with C2139.

In Flusspferd, TestClass is used in places where UndefinedType is not defined, but uses its other constructor:

void test()
{
    A* a = new A();
    TestClass test(a); // will instantiate the templated constructor, but why?
}

TestClass (A * a) , , C2139 - is_convertible.

GCC , : MSVC? ? ?

!

Update:

MSalters . undefined. ++ - :

, , .

template <class T> struct S {
    operator int();
};

void f(int);
void f(S<int>&);
void f(S<float>);

void g(S<int>& sr) {
    f(sr);  // instantiation of S<int> allowed but not required
            // instantiation of S<float> allowed but not required
};
+1
1

, "is_convertible ". , , - , undefined. , GCC, MSVC "" - .

+2

All Articles