开发者

Partial specialization with reference template parameter fails to compile in VS2005

I have code that boils down to the following:

template <typename T> struct Foo {};
template <typename T, const Foo<T>& I> struct FooBar {};

////////

template <typename T> struct Baz {};

template <typename T, const Foo<T>& I>
struct Baz< FooBar<T,I> >
{
 static void func(FooBar<T,I>& value);
};

////////

struct MyStruct
{
 static const Foo<float> s_floatFoo;
};

// Elsewhere: const Foo<float> MyStruct::s_floatFoo;

void callBaz()
{
 typedef FooBar<float, MyStruct::s_floatFoo> FloatFooBar;
 FloatFooBar myFloatFooBar;
 Baz<FloatFooBar>::func(myFloatFooBar);
}

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

error C2039: 'func' 开发者_C百科: is not a member of 'Baz<T>'
        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<float, &MyStruct::s_floatFoo> 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...)


For me it looks like VS2005 uses the first template specification of Baz

template <typename T> struct Baz {};

This struct does indeed not contain a member named func. Looks like VS2005 doesn't deduce the template parameters correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜