Annoying C++ bug in egcs1.1 and egcs-current (egcs-2.92.04 19980911)

Theodore Papadopoulo Theodore.Papadopoulo@sophia.inria.fr
Mon Sep 14 08:01:00 GMT 1998


	IMHO, the following code should compile...

template <class T,char id>
class A {

	static A prototype;

	A() {}

public:

	A(int i) { }
	~A() { }
};

template <class T,char id>
A<T,id> A<T,id>::prototype;

int
main()
{
	A<double,'d'> kk(1);
}
 
I get:
mururoa->/u/corse/2/robotvis/egcs2.6/bin/g++ Error.C
Error.C: In instantiation of `A<double,'d'>':
Error.C:22:   instantiated from here
Error.C:22: aggregate `class A<double,'d'> A<double,'d'>::prototype' has incomplete type and cannot be initialized

The stack at error point is:

#0  start_decl_1 (decl=0x8255f58) at ../../../egcs/gcc/cp/decl.c:6704
#1  0x80641a6 in instantiate_class_template (type=0x8253bbc)
    at ../../../egcs/gcc/cp/pt.c:4532
#2  0x80894dd in complete_type (type=0x8253bbc)
    at ../../../egcs/gcc/cp/typeck.c:158
#3  0x8057edd in grokvardecl (type=0x8253bbc, declarator=0x8253b7c, 
    specbits_in=0xbfffe7b4, initialized=1, constp=0, in_namespace=0x0)
    at ../../../egcs/gcc/cp/decl.c:8188
#4  0x805b16b in grokdeclarator (declarator=0x8253b7c, declspecs=0x8234970, 
    decl_context=NORMAL, initialized=1, attrlist=0x0)
    at ../../../egcs/gcc/cp/decl.c:10656
#5  0x8055fc1 in start_decl (declarator=0x8253b7c, declspecs=0x8234970, 
    initialized=1, attributes=0x0, prefix_attributes=0x0)
    at ../../../egcs/gcc/cp/decl.c:6467
#6  0x80583eb in grokdeclarator (declarator=0x8253b7c, declspecs=0x8234970, 
    decl_context=NORMAL, initialized=0, attrlist=0x0)
    at ../../../egcs/gcc/cp/decl.c:8494
#7  0x8055fc1 in start_decl (declarator=0x8234954, declspecs=0x8234970, 
    initialized=0, attributes=0x0, prefix_attributes=0x0)
    at ../../../egcs/gcc/cp/decl.c:6467
#8  0x80822ea in parse_decl (declarator=0x8234954, specs_attrs=0x8253d3c, 
    attributes=0x0, initialized=0, decl=0xbfffe968) at parse.y:328
#9  0x8084739 in yyparse () at parse.y:1897
#10 0x80a9672 in compile_file (name=0xbffff3cb "Error.ii")
    at ../../egcs/gcc/toplev.c:2773
#11 0x80ac200 in main (argc=8, argv=0xbffff1e0) at ../../egcs/gcc/toplev.c:4846
#12 0x804908b in _start ()

This behaviour is indepedant of the architecture.

AFAIK, it seems that egcs tries to instanciate A<double,'d'> (complete_type?) while 
processing the static member definition and complains because this 
same static variable is not yet defined !!

As I'm stuck by this problem, I'm willing to submit a patch if no-one 
more knowledgable about gcc has time to do it but I need at least a starting hint
(I did not find much information about template instanciation in the 
file gxxint.texi) !!

	Thank's a lot...

	Theo.

 --------------------------------------------------------------------
 Theodore Papadopoulo
 Email: Theodore.Papadopoulo@sophia.inria.fr Tel: (33) 04 92 38 76 01
 --------------------------------------------------------------------






More information about the Gcc-bugs mailing list