compiler bug with templates, VC++2005

Hi,

I think I've found a compiler bug with templates. I've tested this code with VS2003, and VS2005 Beta 2. The following code will produce a warning when compiled, and I can't see any reason for the warning. I've simplified the code as much as possible while it is still producing the warning.

Thanks,
Niall.


c:\documents and settings\niall\my documents\visual studio 2005\projects\test\test\test.cpp(23) : warning C4267: 'argument' : conversion from 'size_t' to 'unsigned int', possible loss of data


void test(size_t x, unsigned int y)
{
}

template<typename T>
struct Traits
{
typedef T Parameter;
};

template<typename A, typename B>
class Functor
{
public:
typedef typename Traits<A>::Parameter Parm1;
typedef typename Traits<B>::Parameter Parm2;
void go(Parm1 p1, Parm2 p2) { test(p1,p2); }
};

void run()
{
size_t x = 100;
unsigned int y = 200;

Functor<size_t, unsigned int> f;
f.go(x,y); //compiler warning on this line!
}



Answer this question

compiler bug with templates, VC++2005

  • btrabucco

    That could be more than just a spurious warning.  The compiler might actually be casting size_t to unsigned, a big no-no on x86-64.

    Melissa

  • Neelanjana

    That's what I initially suspected, but the call chain run->go->test does not mix the two types (size_t and unsigned int).  There's something weird going on with the Traits template.

  • Jollyollyman

    Looks like you're right.  You should submit it via http://lab.msdn.microsoft.com/productfeedback/default.aspx

  • compiler bug with templates, VC++2005