🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac.programmer.codewarrior
Article #591

Re: template default argument bug?

#591
From: Howard Hinnant
Date: Thu, 05 Feb 2004 22:43
48 lines
2803 bytes
In article <4022896d$1@news.kos.net>,
 Edward Chew <ekc-noreply@lgl.kos.net> wrote:

> Here is an example straight out of Stroustrup:
> 
> //----------
> 
> template<class T> class String;
> 
> template<class T> class Cmp {
> public:
> 	static int eq(T a, T b) { return a == b; }
> 	static int lt(T a, T b) { return a < b; }
> };
> 
> template<class T, class C = Cmp<T> >
> int compare(const String<T>& str1, const String<T>& str2);
> 
> //----------
> 
> I compile this in CodeWarrior for Mac OS 8.3 and get:
> 
> Error: illegal use of default template-argument
> 
> If I comment out the /* = Cmp<T> */ it compiles fine.  If I turn the 
> compare function into a class with the same default argument, it is also 
> happy.  Sounds like a compiler bug to me, unless I am missing something 
> obvious.

I think you've found a bug in Bjarne's book.  I looked through his 
errata and didn't see this issue already listed.  If you contact him 
with this information and if you are indeed the first to report it, then 
I'm sure he will be very grateful.  You can search the errata yourself 
at:

http://www.research.att.com/~bs/3rd_errata.html

The C++ standard, section 14.1, paragraph 9 says:

> -9- A default template-argument is a template-argument (temp.arg) specified 
> after = in a template-parameter. A default template-argument may be specified 
> for any kind of template-parameter (type, non-type, template). A default 
> template-argument may be specified in a class template declaration or a class 
> template definition. A default template-argument shall not be specified in a 
> function template declaration or a function template definition, nor in the 
> template-parameter-list of the definition of a member of a class template.

-Howard
Technical Details
Message-ID: <hinnant-B84BAE.17430705022004@syrcnyrdrs-03-ge0.nyroc.rr.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!news-rtr.nyroc.rr.com!news-out.nyroc.rr.com!twister.nyroc.rr.com.POSTED!53ab2750!not-for-mail
References: <4022896d$1@news.kos.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10bcce,7802dbc009c85cd
X-Google-Attributes: gid10bcce,public
X-Google-Thread: f635e,7802dbc009c85cd
X-Google-Attributes: gidf635e,public
X-Google-ArrivalTime: 2004-02-05 14:43:20 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!news-rtr.nyroc.rr.com!news-out.nyroc.rr.com!twister.nyroc.rr.com.POSTED!53ab2750!not-for-mail
From: Howard Hinnant <hinnant@metrowerks.com>
Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac
Subject: Re: template default argument bug?
Organization: Metrowerks
References: <4022896d$1@news.kos.net>
User-Agent: MT-NewsWatcher/3.3b1 (PPC Mac OS X)
Message-ID: <hinnant-B84BAE.17430705022004@syrcnyrdrs-03-ge0.nyroc.rr.com>
Lines: 48
Date: Thu, 05 Feb 2004 22:43:08 GMT
NNTP-Posting-Host: 24.58.14.109
X-Complaints-To: abuse@rr.com
X-Trace: twister.nyroc.rr.com 1076020988 24.58.14.109 (Thu, 05 Feb 2004 17:43:08 EST)
NNTP-Posting-Date: Thu, 05 Feb 2004 17:43:08 EST