Partial specialization with reference template parameter fails to compile in VS2005

Posted by Blair Holloway on Stack Overflow See other posts from Stack Overflow or by Blair Holloway
Published on 2010-05-18T01:58:13Z Indexed on 2010/05/18 2:00 UTC
Read the original article Hit count: 550

I have code that boils down to the following:

template struct Foo {}; template & I> struct FooBar {};

////////

template struct Baz {};

template & I> struct Baz< FooBar > { static void func(FooBar& value); };

////////

struct MyStruct { static const Foo s_floatFoo; };

// Elsewhere: const Foo MyStruct::s_floatFoo;

void callBaz() { typedef FooBar FloatFooBar; FloatFooBar myFloatFooBar; Baz::func(myFloatFooBar); }

This compiles successfully under GCC, however, under VS2005, I get:

error C2039: 'func' : is not a member of 'Baz' with [ T=FloatFooBar ] error C3861: 'func': identifier not found

However, if I change const Foo<T>& I to const Foo<T>* I (passing I by pointer rather than by reference), and defining FloatFooBar as:

typedef FooBar FloatFooBar;

Both GCC and VS2005 are happy.

What's going on? Is this some kind of subtle template substitution failure that VS2005 is handling differently to GCC, or a compiler bug?

(The strangest thing: I thought I had the above code working in VS2005 earlier this morning. But that was before my morning coffee. I'm now not entirely certain I wasn't under some sort of caffeine-craving-induced delirium...)

© Stack Overflow or respective owner

Related posts about templates

Related posts about c++