public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: Template help,To Alexandre Oliva
@ 2000-11-13 19:41 Shiv Shankar Ramakrishnan
  2000-11-13 20:37 ` Alexandre Oliva
  0 siblings, 1 reply; 7+ messages in thread
From: Shiv Shankar Ramakrishnan @ 2000-11-13 19:41 UTC (permalink / raw)
  To: gcc; +Cc: louispp

|you can find such c++ code in VC++.
|in VC++ include directory,the code of file uility

You should read any good book on C++ (Stroustrup) about the rationale
behind the 'typename' keyword. Since that it what has bitten you.
Also see - http://www.ocsltd.com/c++/cpppttyp.html

Such code existing in VC++ includes *does not* mean that -
 1. Such code is 'ISO C++'ly correct
 2. That the compiler doesn't support the 'typename' keyword
 3. That the compiler cannot in theory flag the error

The VC++ compiler does support 'typename'. At least VC6 does. Now its a
different matter that P.J. Plauger and Dinkumware (the implementers of
Std C++ libs for VC++) are not going to give you the correct updated
headers for free. (Complain loudly to them) So the only option I guess
for VC++ was to not flag that as an error. And lets not go into the
whole story behind the mess that Plauger and Tom Plum got all the users
of VC++ into due to their lawsuit ...

|Is there any compile option to avoid the error?

Why don't you try something like this -

#if _MSC_VER >= 1200 //check for the version of your compiler
	#define TYPENAME_ typedef
#else
	#define TYPENAME_ typename
#endif

template <class T1> struct test01 {
  TYPENAME_ T1::Type1 Type1;
};

Its ugly but its one easy way to placate the current situation of
compilers with varying levels of Std ISO C++ support.

I am giving you a detailed answer since most of the other answers that
you have got so far have been very curt ones.

Hope that helps,
Shiv

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Template help,To Alexandre Oliva
  2000-11-13 19:41 Template help,To Alexandre Oliva Shiv Shankar Ramakrishnan
@ 2000-11-13 20:37 ` Alexandre Oliva
  2000-11-13 21:07   ` Shiv Shankar Ramakrishnan
  0 siblings, 1 reply; 7+ messages in thread
From: Alexandre Oliva @ 2000-11-13 20:37 UTC (permalink / raw)
  To: Shiv Shankar Ramakrishnan; +Cc: gcc, louispp

On Nov 14, 2000, "Shiv Shankar Ramakrishnan" <Shiv@pspl.co.in> wrote:

> #if _MSC_VER >= 1200 //check for the version of your compiler
> 	#define TYPENAME_ typedef
> #else
> 	#define TYPENAME_ typename
> #endif

This is wrong.  `typename' is not a replacement for `typedef'.  In
this case, one must use typedef, because a type alias is what the
declaration is going to define, and typename, because it must precede
any template-dependent nested-name-specifiers that are supposed to be
typenames regardless of the template arguments used in an
instantiation.

So, you should define TYPENAME_ to either `typename' or `', and use:

    typedef TYPENAME_ T1::Type1 Type1;

Note that there are other uses of the typename keyword, such as in
template parameters, that should either remain unchanged or be
substituted with the `class' keyword.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: Template help,To Alexandre Oliva
  2000-11-13 20:37 ` Alexandre Oliva
@ 2000-11-13 21:07   ` Shiv Shankar Ramakrishnan
  0 siblings, 0 replies; 7+ messages in thread
From: Shiv Shankar Ramakrishnan @ 2000-11-13 21:07 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc, louispp

|> #if _MSC_VER >= 1200 //check for the version of your compiler
|> 	#define TYPENAME_ typedef
|> #else
|> 	#define TYPENAME_ typename
|> #endif
|
|This is wrong.  `typename' is not a replacement for `typedef'.  In
|this case, one must use typedef, because a type alias is what the
|declaration is going to define, and typename, because it must precede
|any template-dependent nested-name-specifiers that are supposed to be
|typenames regardless of the template arguments used in an
|instantiation.

Oops! You are right. I just shot that off in a hurry. My mistake. Yes a
typedef needs to precede the declaration in the typename case also.
What was I thinking? I guess these things sometimes get tricky and one
can miss out things :( (Esp. is you have used the older way)

So yes it should be -

#if _MSC_VER >= 1200 //check for the version of your compiler
	#define TYPENAME_
#else
	#define TYPENAME_ typename
#endif

And so the use as you pointed becomes -

typedef TYPENAME_ T1::Type1 Type1;


|Note that there are other uses of the typename keyword, such as in
|template parameters, that should either remain unchanged or be
|substituted with the `class' keyword.

Yes. Except that I assumed that the code (being older style) would not
use typename in template parameters. And yes in the other case its
better to change all template parameter uses of typename to the 'class'
keyword than use another ugly macro.

My apologies for causing all the confusion.
Thanks,
Shiv

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Template help,To Alexandre Oliva
@ 2000-11-12 20:40 Liu WS
  0 siblings, 0 replies; 7+ messages in thread
From: Liu WS @ 2000-11-12 20:40 UTC (permalink / raw)
  To: aoliva; +Cc: gcc

Is there any compile option to avoid the error?


>From: Alexandre Oliva <aoliva@redhat.com>
>To: "Liu WS" <louispp@hotmail.com>
>CC: gcc@gcc.gnu.org
>Subject: Re: Template help,To Alexandre Oliva
>Date: 11 Nov 2000 07:32:25 -0200
>
>On Nov 11, 2000, "Liu WS" <louispp@hotmail.com> wrote:
>
> > you can find such c++ code in VC++.
>
>Then please submit a bug report to the maintainers of VC++.  GNU C++
>is correct, since it behaves as mandated by the C++ standard.
>
>--
>Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
>Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
>CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
>Free Software Evangelist    *Please* write to mailing lists, not to me

_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com .

Share information about yourself, create your own public profile at 
http://profiles.msn.com .

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Template help,To Alexandre Oliva
@ 2000-11-11  7:37 Robert Dewar
  0 siblings, 0 replies; 7+ messages in thread
From: Robert Dewar @ 2000-11-11  7:37 UTC (permalink / raw)
  To: aoliva, louispp; +Cc: gcc

<<you can find such c++ code in VC++.
in VC++ include directory,the code of file uility
>>

This is not a criterion of what is or what is not correct C++ !

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Template help,To Alexandre Oliva
  2000-11-11  1:27 Liu WS
@ 2000-11-11  1:32 ` Alexandre Oliva
  0 siblings, 0 replies; 7+ messages in thread
From: Alexandre Oliva @ 2000-11-11  1:32 UTC (permalink / raw)
  To: Liu WS; +Cc: gcc

On Nov 11, 2000, "Liu WS" <louispp@hotmail.com> wrote:

> you can find such c++ code in VC++.

Then please submit a bug report to the maintainers of VC++.  GNU C++
is correct, since it behaves as mandated by the C++ standard.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Template help,To Alexandre Oliva
@ 2000-11-11  1:27 Liu WS
  2000-11-11  1:32 ` Alexandre Oliva
  0 siblings, 1 reply; 7+ messages in thread
From: Liu WS @ 2000-11-11  1:27 UTC (permalink / raw)
  To: gcc

you can find such c++ code in VC++.
in VC++ include directory,the code of file uility

     1 // utility standard header
     2
     3 #if     _MSC_VER > 1000
     4 #pragma once
     5 #endif
....
....
     79 template<class _It>
     80         struct iterator_traits {
     81         typedef _It::iterator_category iterator_category;
     82         typedef _It::value_type value_type;
     83         typedef _It::distance_type distance_type;
     84         };


_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com .

Share information about yourself, create your own public profile at 
http://profiles.msn.com .

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2000-11-13 21:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-13 19:41 Template help,To Alexandre Oliva Shiv Shankar Ramakrishnan
2000-11-13 20:37 ` Alexandre Oliva
2000-11-13 21:07   ` Shiv Shankar Ramakrishnan
  -- strict thread matches above, loose matches on Subject: below --
2000-11-12 20:40 Liu WS
2000-11-11  7:37 Robert Dewar
2000-11-11  1:27 Liu WS
2000-11-11  1:32 ` Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).