This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/5413: g++ fails to understand class template's typedef



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]