[egcs-1.0.1/i586-pc-linux-gnulibc1] g++ and default arguments

Andrew Pollard andrew@odie.demon.co.uk
Fri Jan 9 04:20:00 GMT 1998


Hello,

 I was just porting some old C++ code to go through egcs/g++ when I
stumbled across this (a much reduced example from the actual code...)

a.cc:
-------------------------------------------------------------------------------
struct A {
        A() {}
};
struct B {
        A* a;
        B(A* _a = new A()) { a = _a; }	// line 6
};
void foo() {
        B* b1 = new B();		// line 9
        B* b2 = new B(new A());
}
-------------------------------------------------------------------------------
% g++ -v
Reading specs from /usr/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.23/specs
gcc version egcs-2.90.23 980102 (egcs-1.0.1 release)
% g++ -c a.cc
a.cc:6: sorry, not implemented: `try_catch_expr' not supported by dump_expr
a.cc:9: sorry, not implemented: initializer contains unrecognized tree code
% g++ -c -fno-exceptions a.cc
%

Note how there is a problem with the default argument to B's
constructor and a problem in new'ing b1, but 'inlining' it myself when
new'ing b2 works...

It also works under gcc-2.7.2.2 (both with and without -fhandle-exceptions)

It's not a problem (I just fixed the original code), but I was quite
surprised.

Any comments from the people who know the g++ front end?

[ BTW - It's a terrible bit of code - but I didn't write it :-) ]

Andrew.
--
   Andrew Pollard, Auto Simulations Ltd. UK.    | home: andrew@odie.demon.co.uk
   2 Milbanke Court, Milbanke Way, Bracknell    | work: andrewp@autosim.com
Tel:+44(0)1344 426486x103 Fax:+44(0)1344 426615 | http://www.odie.demon.co.uk





More information about the Gcc mailing list