template function default parameter instantiated unnecessary

Hi,

I think the following is valid C++ code. The default parameter of template (member) function should not be instantiated until it is actually required.

Is it a bug of CC?

$ cat enumid.cc

template<class T>

class TClass

{

public:

void f(int i = T::EnumID);

};

class Unknown;

class X

{

public:

TClass<Unknown> m;

};

$ CC -c enumid.cc

"enumid.cc", line 5: Error: EnumID is not a member of Unknown.

"enumid.cc", line 11:Where: While specializing "TClass<Unknown>".

"enumid.cc", line 11:Where: Specialized in non-template code.

1 Error(s) detected.

$ CC -V

CC: Sun C++ 5.8 2005/10/13

Thanks,

Qingning

[767 byte] By [huoq] at [2007-11-26 10:56:31]
# 1

You are right. This test case is valid and shows compiler bug

C++ Standard 14.7.1-1

The implicit instantiation of a class template specialization causes the implicit instantiation of the declarations, but not of the definitions or default arguments, of the class member functions, member classes, static data members and member templates; and it causes the implicit instantiation of the definitions of member anonymous unions.

If you have a service contract with Sun, please file a bug report via your service channel. You can be kept informed about progress, and get pre-release versions of the compiler that fix the bug.

If you don't have a service contract with Sun, please file a bug report at bugs.sun.com.

If you prefer not to file the bug report yourself, let me know, and I'll file one for you.

Atanasyan at 2007-7-7 3:09:43 > top of Java-index,Development Tools,Solaris and Linux Development Tools...