🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.mac.programmer.codewarrior
11 messages
11 total messages Started by Edward Chew Thu, 05 Feb 2004 18:21
template default argument bug?
#590
Author: Edward Chew
Date: Thu, 05 Feb 2004 18:21
27 lines
1959 bytes
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.

-Ted
Re: template default argument bug?
#591
Author: 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
Re: template default argument bug?
#592
Author: Edward Chew
Date: Fri, 06 Feb 2004 17:22
32 lines
2421 bytes
Howard Hinnant wrote:

> 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.

What?  My C++ Bible has failed me?  Say it isn't so!  ;-)  I wonder how 
may editions this affects?  This is the one I have:

The C++ Programming Language: Special Edition
Bjarn Stroustrup
Copyright 2000 by AT&T
ISBN 0-201-70073-5

The offending example was in section 13.4.1 (page 340).

Why do you suppose they don't allow default arguments in template 
functions anyway?  They would certainly be useful.

Ah well, so how about this one?  If I instantiate something along the lines:

	TB<int,TA<int>> b;

I get "Error: illegal template argument(s)".  This error vanishes if I 
add one space like so:

	TB<int,TA<int> > b;

Is this a compiler bug or another quirk in C++ (again, I am using CW 8.3)?

-Ted
Re: template default argument bug?
#593
Author: MW Ron
Date: Fri, 06 Feb 2004 18:49
26 lines
1798 bytes
In article <4023cd0a$1@news.kos.net>,
 Edward Chew <ekc-noreply@lgl.kos.net> wrote:


>Ah well, so how about this one?  If I instantiate something along the lines:
>
>	TB<int,TA<int>> b;
>
>I get "Error: illegal template argument(s)".  This error vanishes if I 
>add one space like so:
>
>	TB<int,TA<int> > b;
>
>Is this a compiler bug or another quirk in C++ (again, I am using CW 8.3)?

A space is mandatory  because the shift operator  >> has higer 
precedence  so it would be parsed sooner.

this is a pretty frequent questions with peopld doing templates :)

Ron

-- 

Metrowerks, maker of CodeWarrior   -  "Software Starts Here"  
Ron Liechty - MWRon@metrowerks.com - <http://www.metrowerks.com>
Re: template default argument bug?
#594
Author: Miro Jurisic
Date: Fri, 06 Feb 2004 20:46
15 lines
1487 bytes
In article <mwron-5C8DDF.13492406022004@news.newsguy.com>,
 MW Ron <mwron@metrowerks.com> wrote:

> A space is mandatory  because the shift operator  >> has higer 
> precedence  so it would be parsed sooner.
> 
> this is a pretty frequent questions with peopld doing templates :)

This is also going to be fixed in the next version of the C++ standard

meeroh

-- 
If this message helped you, consider buying an item
from my wish list: <http://web.meeroh.org/wishlist>
Re: template default argument bug?
#595
Author: Steve
Date: Fri, 06 Feb 2004 22:04
28 lines
2071 bytes
On 6/2/04 8:46 pm, in article
macdev-CB175B.15465006022004@senator-bedfellow.mit.edu, "Miro Jurisic"
<macdev@meeroh.org> wrote:

> In article <mwron-5C8DDF.13492406022004@news.newsguy.com>,
> MW Ron <mwron@metrowerks.com> wrote:
> 
>> A space is mandatory  because the shift operator  >> has higer
>> precedence  so it would be parsed sooner.
>> 
>> this is a pretty frequent questions with peopld doing templates :)
> 
> This is also going to be fixed in the next version of the C++ standard
> 
> meeroh

How will the following be interpreted?

template< int N >
class A ...

template< class T = A< 64 >> 2 > >
class ...

(imagine brackets around 64 >> 2)


Steve.
Re: template default argument bug?
#596
Author: Miro Jurisic
Date: Fri, 06 Feb 2004 22:18
29 lines
1751 bytes
In article <BC49C007.5810C%postmaster@127.0.0.1>, Steve <postmaster@127.0.0.1> 
wrote:

> How will the following be interpreted?
> 
> template< int N >
> class A ...
> 
> template< class T = A< 64 >> 2 > >
> class ...
> 
> (imagine brackets around 64 >> 2)

I assume you will have to put the 64>>2 in ()s, just as you have to do with this 
right now:

template< int N >
class A ...

template< class T = A< 64 > 2 > >
class ...

(But I don't know that this is the outcome the committee will choose)

meeroh

-- 
If this message helped you, consider buying an item
from my wish list: <http://web.meeroh.org/wishlist>
Re: template default argument bug?
#597
Author: Steve
Date: Fri, 06 Feb 2004 22:39
37 lines
2383 bytes
On 6/2/04 10:18 pm, in article
macdev-84B047.17184506022004@senator-bedfellow.mit.edu, "Miro Jurisic"
<macdev@meeroh.org> wrote:

> In article <BC49C007.5810C%postmaster@127.0.0.1>, Steve <postmaster@127.0.0.1>
> wrote:
> 
>> How will the following be interpreted?
>> 
>> template< int N >
>> class A ...
>> 
>> template< class T = A< 64 >> 2 > >
>> class ...
>> 
>> (imagine brackets around 64 >> 2)
> 
> I assume you will have to put the 64>>2 in ()s, just as you have to do with
> this 
> right now:
> 
> template< int N >
> class A ...
> 
> template< class T = A< 64 > 2 > >
> class ...
> 
> (But I don't know that this is the outcome the committee will choose)
> 
> meeroh

Of course! I was concentrating too much on >> ! :)

Do you have any website links about this?

Cheers,
Steve.
Re: template default argument bug?
#598
Author: Miro Jurisic
Date: Fri, 06 Feb 2004 23:46
12 lines
1529 bytes
In article <BC49C83B.58156%postmaster@127.0.0.1>, Steve <postmaster@127.0.0.1> 
wrote:

> Do you have any website links about this?

Nope, word of mouth via my committee friends is all I have at this point.

meeroh

-- 
If this message helped you, consider buying an item
from my wish list: <http://web.meeroh.org/wishlist>
Re: template default argument bug?
#599
Author: Bjarne Stroustrup
Date: Fri, 06 Feb 2004 23:53
26 lines
2213 bytes
Edward Chew <ekc-noreply@lgl.kos.net> wrote in message news:<4023cd0a$1@news.kos.net>...
> Howard Hinnant wrote:
> 
> > 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.
> 
> What?  My C++ Bible has failed me?  Say it isn't so!  ;-)  I wonder how 
> may editions this affects?  This is the one I have:
> 
> The C++ Programming Language: Special Edition
> Bjarn Stroustrup
> Copyright 2000 by AT&T
> ISBN 0-201-70073-5
> 
> The offending example was in section 13.4.1 (page 340).

Things are a little bit mor ecomplicated than that. The restriction in
the standard was basically an oversight. You'll find the problem
mentioned on my "issues" page. The committee has voted to correct this
(i.e. make my book correct), but the vote can't take effect until a
new revision of the standard are issued. My view is that you found a
bug in the standard (that the committee already has corrected :-)

  - Bjarne Stroustrup; http://www.research.att.com
Re: template default argument bug?
#600
Author: Howard Hinnant
Date: Sat, 07 Feb 2004 01:47
17 lines
1820 bytes
In article <188b3370.0402061553.7cefc0f7@posting.google.com>,
 bs@research.att.com (Bjarne Stroustrup) wrote:

> Things are a little bit mor ecomplicated than that. The restriction in
> the standard was basically an oversight. You'll find the problem
> mentioned on my "issues" page. The committee has voted to correct this
> (i.e. make my book correct), but the vote can't take effect until a
> new revision of the standard are issued. My view is that you found a
> bug in the standard (that the committee already has corrected :-)

Ahh...

http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#226

Thank you for bringing this to my attention.

-Howard
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads