From: gbilkus@jpmorgan.COM (Gary Bilkus)
Subject: Template bugs in gcc 2.3.1 c++ compiler
Organization: GNUs Not Usenet
Distribution: gnu
Date: Tue, 10 Nov 1992 17:50:05 GMT

I have had some difficulty with templates using version 2.3.1 of gcc. 

Problem 1.
Consider the following simple program.
----------------------------------------------------------
template<class keytype>
class testlist
{
public:
  testlist(int k);
  ~testlist();
};

template<class keytype>
inline testlist<keytype>::testlist(int k) {};

template<class keytype>
inline testlist<keytype>::~testlist()  {};


main()
{
testlist<int> l1(0);
testlist<double> l2(0);
};
----------------------------------------------------------

If I compile this under gcc 2.2.2 all is fine.
Under 2.3.1 I get the following ( sparc and sunos 4.1.2 but I'm
pretty sure this is platform independent )

Reading specs from /public/lib/gcc-lib/sparc/2.3.1/specs
gcc version 2.3.1
 /public/lib/gcc-lib/sparc/2.3.1/cpp -lang-c++ -v -undef -D__GNUC__=2
 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ 
-D__unix__ -D__sparc -D__sun -D__unix bug.cc /usr/tmp/cca10725.i
GNU CPP version 2.3.1 (sparc)
 /public/lib/gcc-lib/sparc/2.3.1/cc1plus /usr/tmp/cca10725.i -quiet -dumpbase
 bug.cc -version -o /usr/tmp/cca10725.s
GNU C++ version 2.3.1 (sparc) compiled by GNU C version 2.3.1.
bug.cc: In function `int  main ()':
bug.cc:7: inconsistent return types for method `testlist' in class
 `testlist<int>'
bug.cc:7: inconsistent return types for method `testlist' in class
 `testlist<double>'
gcc: Internal compiler error: program cc1plus got fatal signal 11

A gdb of the core gives the following:
-----------------------------------------------------------
Core was generated by `cc1plus'.
Program terminated with signal 11, Segmentation fault.
#0  expand_expr (exp=0x0, target=0x0, tmode=VOIDmode, modifier=EXPAND_NORMAL)
    at expr.c:3249
3249      tree type = TREE_TYPE (exp);
(gdb) bt
#0  expand_expr (exp=0x0, target=0x0, tmode=VOIDmode, modifier=EXPAND_NORMAL)
    at expr.c:3249
#1  0xa4c10 in expand_expr (exp=0x187050, target=0x0, tmode=VOIDmode, 
    modifier=EXPAND_NORMAL) at expr.c:5222
#2  0xa6d78 in do_jump (exp=0x187050, if_false_label=0x188cf8, 
    if_true_label=0x0) at expr.c:6625
#3  0xa6684 in jumpifnot (exp=0x187050, label=0x188cf8) at expr.c:6355
#4  0xa449c in expand_expr (exp=0x1870b8, target=0x0, tmode=1608984, 
    modifier=EXPAND_NORMAL) at expr.c:4903
#5  0x974bc in expand_expr_stmt (exp=0x1870b8) at stmt.c:1315
#6  0x25ff8 in finish_function (lineno=13, call_poplevel=1732472)
    at cp-decl.c:10456
#7  0xe698 in yyparse () at cp-parse.y:596
#8  0x7dd80 in compile_file (name=0xf7fffa8c "/usr/tmp/cca10725.i")
    at toplev.c:1804
#9  0x80908 in main (argc=8, argv=0xf7fff9d4, envp=0xf7fff9f8) at toplev.c:3283
-----------------------------------------------------------

Further investigation reveals that the problem is in the code of cp-pt.c
somewhere around line 1153 where the inconsistent return types error
message is generated. This whole section is changed from 2.2.2 and seems
to do the wrong thing with constructors with arguments.
 
Presumably, also, something isn't reset right after the error, which
leads to the crash.

Commenting out the relevant test appears to fix the problem, but
I'm sure this isn't the right thing to do. Any better fixes?
------------------------------------------------------------

The second problem relates to template functions rather than classes
gcc 2.3.1 appears no longer to name mangle these at all. 
The following program
------------------------------------------------------------
template<class keytype>
static inline void do_it(keytype k) {};

main()
{
int i;
double d;
do_it(i);
do_it(d);
};
------------------------------------------------------------

works fine under 2.2.2 generating two different versions of do_it
with name mangled names.
2.3.1 gives an error on assembly of:
as: "/usr/tmp/cca10780.s", line 43: error: redefinition of symbol "_do_it"

caused because it doesn't mangle the name and gets the same answer both times.

Any answers?

Gary Bilkus
(bilkus_gary@jpmorgan.com)

Newsgroups: gnu.g++.bug