public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/5413: g++ fails to understand class template's typedef
@ 2002-01-17 10:54 paolo
  0 siblings, 0 replies; 5+ messages in thread
From: paolo @ 2002-01-17 10:54 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, wirawan0

Synopsis: g++ fails to understand class template's typedef

State-Changed-From-To: open->closed
State-Changed-By: paolo
State-Changed-When: Thu Jan 17 10:54:30 2002
State-Changed-Why:
    Does not affect both 3.0.3 and current 3.1 snapshots.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5413


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

* Re: c++/5413: g++ fails to understand class template's typedef
@ 2002-01-17 10:46 Andrew Pinski
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Pinski @ 2002-01-17 10:46 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/5413; it has been noted by GNATS.

From: Andrew Pinski <pinskia@physics.uc.edu>
To: "Wirawan Purwanto" <wirawan@camelot.physics.wm.edu>
Cc: <gcc-gnats@gcc.gnu.org>, <gcc-prs@gcc.gnu.org>, <wirawan0@hotmail.com>,
   <gcc-bugs@gcc.gnu.org>, <nobody@gcc.gnu.org>
Subject: Re: c++/5413: g++ fails to understand class template's typedef
Date: Thu, 17 Jan 2002 13:42:04 -0500

 This bug was fixed in at least 3.0.4 (which might be released?, but as
 you said it was fixed in gcc 2.96 so it most likely was fixed in gcc 
 3.0).
 
 Thanks,
 Andrew Pinski
 On Thursday, January 17, 2002, at 01:16 , Wirawan Purwanto wrote:
 
 > Please see attachment. Hopefully the attachment is not stripped again.
 >
 > xref:
 > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-
 > trail&database=gcc&p
 > r=5413
 >
 


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

* Re: c++/5413: g++ fails to understand class template's typedef
@ 2002-01-17 10:26 Wirawan Purwanto
  0 siblings, 0 replies; 5+ messages in thread
From: Wirawan Purwanto @ 2002-01-17 10:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/5413; it has been noted by GNATS.

From: "Wirawan Purwanto" <wirawan@camelot.physics.wm.edu>
To: <gcc-gnats@gcc.gnu.org>,
	<gcc-prs@gcc.gnu.org>,
	<wirawan0@hotmail.com>,
	<gcc-bugs@gcc.gnu.org>,
	<nobody@gcc.gnu.org>
Cc:  
Subject: Re: c++/5413: g++ fails to understand class template's typedef
Date: Thu, 17 Jan 2002 13:16:29 -0500

 This is a multi-part message in MIME format.
 
 ------=_NextPart_000_0049_01C19F59.2CFA9550
 Content-Type: text/plain;
 	charset="iso-8859-1"
 Content-Transfer-Encoding: 7bit
 
 Please see attachment. Hopefully the attachment is not stripped again.
 
 xref:
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&p
 r=5413
 
 ------=_NextPart_000_0049_01C19F59.2CFA9550
 Content-Type: application/octet-stream;
 	name="gcc-template-bug1.cpp"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment;
 	filename="gcc-template-bug1.cpp"
 
 /*
 
 Help GCC developer!
 
 I found an annoying bug in g++ recently. A simplified test program is
 attached. This file alone is enough to reproduce the error.
 
 I have tested this program under the following compilers:
 
 1. g++ 2.95.2, mingw32 distribution. Typing "g++ -v" returns:
 
    Reading specs from =
 e:\APPS\GCC2.95.2\BIN\..\lib\gcc-lib\mingw32\2.95.2\specs
    gcc driver version 2.95.2 19991024 (release) executing gcc version =
 2.95.2-mingw
    snapshot 20010329
 
 2. g++ 2.95.3-6, distributed in mingw32 version 1.1. Typing "g++ -v" =
 returns:
 
    Reading specs from =
 c:/usr/gcc/bin/../lib/gcc-lib/mingw32/2.95.3-6/specs
    gcc version 2.95.3-6 (mingw special)
 
 3. g++ 2.95.3, in Mandrake Linux version . Typing "g++ -v" returns:
 
    Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux/2.95.3/specs
    gcc version 2.95.3 19991030 (prerelease)
 
 This error is related to the template feature in the compiler.
 The error can be briefly desrcribed as follows:
 
 Suppose we declare a class template called PARENT, and in this class we
 make a typedef PARENT_type. Any type should work (I have tried arrays
 and structs and ints).
 
 Then we declare another class template, called CHILD, whose base class
 is _another_ class template (given in the template parameter of CHILD).
 Now we want to use the typedefs declared in the base class. For example,
 here I typed:
 
   typedef typename parent_template<payload_data>::PARENT_type =
 CHILD_type1;
 
 in the declaration of class CHILD. This is OK as long as we use
 CHILD_type1 within the declaration of the class. But once we declare it
 OUTSIDE the class declaration (i.e. in the definition of method
 
   CHILD<parent_template>::this_is_refused(CHILD_type1 xx)           <--+
                                                                        |
 below, the compiler complains (line number can vary, but it refers to  |
 the line containing { } after the statement above): -------------------+
 
   gcc-template-bug1.cpp:100: `parent_template<payload_data>' is not a
   class, struct, or union type
   gcc-template-bug1.cpp:100: syntax error before `{'
 
 The fact that parent_template<payload_data> is used as a base class
 implies that parent_template<payload_data> must be a class. Why can't we
 assume that here? BTW I have checked this testcase against Borland C++ =
 5.5
 and Compaq C++ (in Alpha machine), they don't complain about this. Also
 ecgs 2.96 for linux-alpha does not complain--but AFAIK this version is
 not supported.
 
 Please help me! Is there any solution or patch to this problem? I would
 appreciate if you cc: also your reply to my address below.
 
 Wirawan
 <wirawan0@hotmail.com>
 
  */
 
 template <class Payload =3D int>
 class PARENT
 {
 public:
 //  this is a custom typedef defined in the parent
     typedef int PARENT_type;
 //  this is an "extra" payload that can be customized by the user
     Payload Data;
 };
 
 // this is the custom payload, defined by the user
 struct payload_data { int x; };
 
 // now we use the PARENT class template to define the CHILD. But here
 // the CHILD will have a _specific_ payload (don't ask why---I did =
 employ
 // this organization in my own program).
 template <template <class e> class parent_template>
 class CHILD: public parent_template<payload_data>
 {
 public:
     //    typedef typeof(typename =
 parent_template<payload_data>::PARENT_type) CHILD_type1;
 //    typedef parent_template<payload_data> prnt;
 //    typedef typename prnt::PARENT_type CHILD_type1;
     typedef typename parent_template<payload_data>::PARENT_type =
 CHILD_type1;
     typedef int CHILD_type2[4];
     void this_is_fine(CHILD_type2 xx);
     void this_is_refused(CHILD_type1 xx); // this is not regarded as =
 error
 };
 
 template <template <class e> class parent_template>
 void CHILD<parent_template>::this_is_fine(CHILD_type2 xx)
 { }
 
 template <template <class e> class parent_template>
 void CHILD<parent_template>::this_is_refused(CHILD_type1 xx)
 { }                          // ^ but above line is regarded as =
 erroneous!
 
 CHILD<PARENT> sistem;
 
 int main()
 {
     CHILD<PARENT>::PARENT_type uu;                  // however, this is =
 OK
     PARENT<double>::PARENT_type xyz;
     return 0;
 }
 
 ------=_NextPart_000_0049_01C19F59.2CFA9550--


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

* Re: c++/5413: g++ fails to understand class template's typedef
@ 2002-01-17  8:46 Paolo Carlini
  0 siblings, 0 replies; 5+ messages in thread
From: Paolo Carlini @ 2002-01-17  8:46 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/5413; it has been noted by GNATS.

From: Paolo Carlini <pcarlini@unitus.it>
To: gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org,
	wirawan0@hotmail.com, gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org
Cc:  
Subject: Re: c++/5413: g++ fails to understand class template's typedef
Date: Thu, 17 Jan 2002 17:44:25 +0100

 For some reason, the attachment got lost.
 
 Could you possibly provide it by viewing your PR from 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl and then using " send email to 
 interested parties 
 <mailto:gcc-gnats%40gcc.gnu.org%2C%20gcc-prs%40gcc.gnu.org%2C%20wirawan0%40hotmail.com%2C%20gcc-bugs%40gcc.gnu.org%2C%20nobody%40gcc.gnu.org?Subject=Re%3A%20c%2B%2B%2F5413%3A%20g%2B%2B%20fails%20to%20understand%20class%20template%27s%20typedef&Body=http%3A%2F%2Fgcc.gnu.org%2Fcgi-bin%2Fgnatsweb.pl%3Fcmd%3Dview%2520audit-trail%26database%3Dgcc%26pr%3D5413>" 
 ??
 
 Thanks,
 Paolo.
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5413 
 
 


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

* c++/5413: g++ fails to understand class template's typedef
@ 2002-01-17  8:16 wirawan0
  0 siblings, 0 replies; 5+ messages in thread
From: wirawan0 @ 2002-01-17  8:16 UTC (permalink / raw)
  To: gcc-gnats


>Number:         5413
>Category:       c++
>Synopsis:       g++ fails to understand class template's typedef
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Thu Jan 17 08:16:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Wirawan Purwanto
>Release:        gcc-2.95.3-5 and gcc-2.95.3-6
>Organization:
>Environment:
mingw32 1.1 (gcc-2.95.3-6), but also other gcc 2.95.x
>Description:
Help GCC developer! [pls read with fixed-width font; the same document could also be found in the attachment]

I found an annoying bug in g++ recently. A simplified test program is
supplied below. This file alone is enough to reproduce the error.

I have tested this program under the following compilers:

1. g++ 2.95.2, mingw32 distribution. Typing "g++ -v" returns:

   Reading specs from e:\APPS\GCC2.95.2\BIN\..\lib\gcc-lib\mingw32\2.95.2\specs
   gcc driver version 2.95.2 19991024 (release) executing gcc version 2.95.2-mingw
   snapshot 20010329

2. g++ 2.95.3-6, distributed in mingw32 version 1.1. Typing "g++ -v" returns:

   Reading specs from c:/usr/gcc/bin/../lib/gcc-lib/mingw32/2.95.3-6/specs
   gcc version 2.95.3-6 (mingw special)

3. g++ 2.95.3, in Mandrake Linux version . Typing "g++ -v" returns:

   Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux/2.95.3/specs
   gcc version 2.95.3 19991030 (prerelease)

This error is related to the template feature in the compiler.
The error can be briefly desrcribed as follows:

Suppose we declare a class template called PARENT, and in this class we
make a typedef PARENT_type. Any type should work (I have tried arrays
and structs and ints).

Then we declare another class template, called CHILD, whose base class
is _another_ class template (given in the template parameter of CHILD).
Now we want to use the typedefs declared in the base class. For example,
here I typed:

  typedef typename parent_template<payload_data>::PARENT_type CHILD_type1;

in the declaration of class CHILD. This is OK as long as we use
CHILD_type1 within the declaration of the class. But once we declare it
OUTSIDE the class declaration (i.e. in the definition of method

  CHILD<parent_template>::this_is_refused(CHILD_type1 xx)           <--+
                                                                       |
below, the compiler complains (line number can vary, but it refers to  |
the line containing { } after the statement above): -------------------+

  gcc-template-bug1.cpp:100: `parent_template<payload_data>' is not a
  class, struct, or union type
  gcc-template-bug1.cpp:100: syntax error before `{'

The fact that parent_template<payload_data> is used as a base class
implies that parent_template<payload_data> must be a class. Why can't we
assume that here? BTW I have checked this testcase against Borland C++ 5.5
and Compaq C++ (in Alpha machine), they don't complain about this. Also
ecgs 2.96 for linux-alpha does not complain--but AFAIK this version is
not supported.

Please help me! Is there any solution or patch to this problem? I would
appreciate if you cc: also your reply to my address below.

Wirawan
<wirawan0@hotmail.com>
>How-To-Repeat:
See attached file, all are there.
>Fix:
Temporary workaround is by create the definition of the class method INSIDE the declaration of class. But this is nasty for large methods!
>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2002-01-17 18:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-17 10:54 c++/5413: g++ fails to understand class template's typedef paolo
  -- strict thread matches above, loose matches on Subject: below --
2002-01-17 10:46 Andrew Pinski
2002-01-17 10:26 Wirawan Purwanto
2002-01-17  8:46 Paolo Carlini
2002-01-17  8:16 wirawan0

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