Partial specialisation bug in SS11?

Hi,

I think I may have found a bug in SunStudio 11 related to partial specialisation. However the whole concept of partial specialisation is so confusing I can't be sure. Can someone out there tell me whether my code is broken or the compiler is broken.

FYI gcc don't seem to have a problem with the code, and compiles it happly.

Microsoft Visual Studio does have a problem and gives a similar error.

Many thanks

Neil.

When I compile the following I get the error

% CC -V partialSpecialisation.cc

CC: Sun C++ 5.8 Patch 121018-11 2007/05/02

ccfe: Sun C++ 5.8 Patch 121018-11 2007/05/02

"partialSpecialisation.cc", line 10: Error: Partial specialization parameter T is not used in the arguments.

1 Error(s) detected.

============ partialSpecialisation.cc =================

template <typename T> class Traits {};

template <typename T>

class Stuff

{

public:

struct Data {};

};

template <typename T>

class Traits<typename Stuff><T>::Data>

{

};

======================================

[1166 byte] By [neil57a] at [2007-11-27 9:28:38]
# 1

Actually g++ just does not point to the root of the problem but shows an error on the next step. Take a look at following test case. Though argument of Traits is Stuff<double>::Data compiler cannot find partial specialization and so cannot find declaration of 'foo' member function.

[code]

% cat test.cc

template <typename T> class Traits {};

template <typename T>

struct Stuff

{

struct Data {};

};

template <typename T>

struct Traits<typename Stuff><T>::Data>

{

void foo() {}

};

int main()

{

Traits<Stuff><double>::Data> t;

t.foo();

}

% g++ -c test.cc

test.cc: In function 'int main()':

test.cc:18: error: 'class Traits<Stuff><double>::Data>' has no member named 'foo'

[/code]

When you use dependent type as a partial specialization argument compiler cannot deduce template argument T. Well exactly in that test case it is possible but in general it is quite dangerous, unpredictable and sometimes impossible way.

Suppose you define specialization of class Stuff where 'typedef int Data'. Also take into account that all these specialization can be defined by different programmers in different libraries. What kind of specialization should compiler select for 'Traits<Stuff><int>::Data>'? Will this choice the same as the author of function 'main' expect?

[code]

template <typename T> class Traits {};

template <typename T>

struct Stuff

{

struct Data {};

};

template <>

struct Stuff<int>

{

typedef int Data;

};

template <typename T>

struct Traits<typename Stuff><T>::Data>

{

void foo() {}

};

int main()

{

Traits<Stuff><int>::Data> t;

t.foo();

}

[/code]

Atanasyana at 2007-7-12 22:34:17 > top of Java-index,Development Tools,Solaris and Linux Development Tools...