Metrowerks: member template specialization problem

I get the following error from metrowerks: http://tinyurl.com/2z6st It seems that given: template<> bool basic_config_file_iterator<wchar_t>::getline(std::string& s); template<class charT> bool basic_config_file_iterator<charT>::getline(std::string& s) { return std::getline(*is, s); } Metrowerks decides to use the second, unspecialized version, even for basic_config_file_iterator<wchar_t>, and this surely fails to compile. Anybody knows what could be the reason? The entire header which causes the error can be found at: http://tinyurl.com/2rapj Thanks in advance, Volodya

On May 27, 2004, at 3:20 AM, Vladimir Prus wrote:
I get the following error from metrowerks:
It seems that given:
template<> bool basic_config_file_iterator<wchar_t>::getline(std::string& s);
template<class charT> bool basic_config_file_iterator<charT>::getline(std::string& s) { return std::getline(*is, s); }
Metrowerks decides to use the second, unspecialized version, even for basic_config_file_iterator<wchar_t>, and this surely fails to compile.
Anybody knows what could be the reason? The entire header which causes the error can be found at:
I've sent a reduced test case to the Metrowerks front end engineer. In the meantime I can think of two workarounds: 1. Specialize the entire basic_config_file_iterator class on wchar_t. or 2. Provide an inlined definition for the specialized member in the header. -Howard

Howard Hinnant wrote:
It seems that given:
template<> bool basic_config_file_iterator<wchar_t>::getline(std::string& s);
template<class charT> bool basic_config_file_iterator<charT>::getline(std::string& s) { return std::getline(*is, s); }
Metrowerks decides to use the second, unspecialized version, even for basic_config_file_iterator<wchar_t>, and this surely fails to compile.
I've sent a reduced test case to the Metrowerks front end engineer.
Thanks.
In the meantime I can think of two workarounds:
1. Specialize the entire basic_config_file_iterator class on wchar_t. or
This might be a good idea, especially since two other compilers -- borland and VC7 have problems with the same member function specialization.
2. Provide an inlined definition for the specialized member in the header.
Do you think that would help? - Volodya

On May 27, 2004, at 10:05 AM, Vladimir Prus wrote:
I've sent a reduced test case to the Metrowerks front end engineer.
Thanks.
In the meantime I can think of two workarounds:
1. Specialize the entire basic_config_file_iterator class on wchar_t. or
This might be a good idea, especially since two other compilers -- borland and VC7 have problems with the same member function specialization.
2. Provide an inlined definition for the specialized member in the header.
Do you think that would help?
Here's my reduced test case: #include <string> struct base { virtual bool getline(std::string& s) = 0; }; template <class charT> struct derived : public base { bool getline(std::string& s); }; template <> //inline bool derived<wchar_t>::getline(std::string&);// {return false;} template <class charT> bool derived<charT>::getline(std::string&) { char test[sizeof(charT) == 1]; return true; } int main() { std::string s; derived<char> c; c.getline(s); derived<wchar_t> w; w.getline(s); } Error : data type is incomplete (instantiating: 'derived<wchar_t>::getline(std::basic_string<char, std::char_traits<char>, std::allocator<char>> &)') HelloWorld.cp line 24 char test[sizeof(charT) == 1]; If I give the specialization a definition, it compiles and runs correctly at least on Pro 9. Sorry I don't have Pro 8 loaded to test on. Btw our FE engineer has gotten back to me, confirmed this is a bug, and it has already been fixed in our latest compiler (post-Pro 9, not yet released). -Howard

Howard Hinnant wrote:
Here's my reduced test case: ... template <> //inline bool derived<wchar_t>::getline(std::string&);// {return false;}
If I give the specialization a definition, it compiles and runs correctly at least on Pro 9. Sorry I don't have Pro 8 loaded to test on.
Thanks for testing this. I need to decide if I really want to support borland and VC7, and if not, I'll just apply this workaround. Otherwise, I'll have to give up member specialization :-(
Btw our FE engineer has gotten back to me, confirmed this is a bug, and it has already been fixed in our latest compiler (post-Pro 9, not yet released).
Good to know! Thanks, Volodya

On 5/27/04 3:20 AM, "Vladimir Prus" <ghost@cs.msu.su> wrote:
I get the following error from metrowerks:
Unless you already altered the files, this error and the problem below don't look related. For this error, are you sure you #included <string>? Or maybe the previous line/statement wasn't ended correctly.
It seems that given:
template<> bool basic_config_file_iterator<wchar_t>::getline(std::string& s);
template<class charT> bool basic_config_file_iterator<charT>::getline(std::string& s) { return std::getline(*is, s); }
Metrowerks decides to use the second, unspecialized version, even for basic_config_file_iterator<wchar_t>, and this surely fails to compile.
Anybody knows what could be the reason? The entire header which causes the error can be found at:
Is the first version supposed to mean anything? Are you allowed to "specialize" a specific class member function _instead_ of specializing the entire class? (i.e. Make a new basic_config_file_iterator<wchar_t> class specialization instead of just one method.) -- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com

Daryle Walker wrote:
On 5/27/04 3:20 AM, "Vladimir Prus" <ghost@cs.msu.su> wrote:
I get the following error from metrowerks:
Unless you already altered the files, this error and the problem below don't look related.
I've altered the files already.
For this error, are you sure you #included <string>? Or maybe the previous line/statement wasn't ended correctly.
Yes, I think something like this is the cause for the new error.
It seems that given:
template<> bool basic_config_file_iterator<wchar_t>::getline(std::string& s);
template<class charT> bool basic_config_file_iterator<charT>::getline(std::string& s) { return std::getline(*is, s); }
Is the first version supposed to mean anything?
Well, yes.
Are you allowed to "specialize" a specific class member function _instead_ of specializing the entire class? (i.e. Make a new basic_config_file_iterator<wchar_t> class specialization instead of just one method.)
Yes, the standard allows it, and a number of compilers (gcc, vc7.1, comeau) have no problems with it. - Volodya
participants (3)
-
Daryle Walker
-
Howard Hinnant
-
Vladimir Prus