[H-GEN] g++/egcs peculiarity
Craig Eldershaw
ce at comlab.ox.ac.uk
Thu May 14 06:01:02 EDT 1998
Hi All,
OK, here's a short C++ program:
=========================================
class myclass
{
public:
myclass(int x, int y)
{}
};
int main()
{
int *first=new int(5); // create an int
int *second=new int[10](5); // create 10 ints
myclass *one=new myclass(1,2); // create a myclass
myclass *two=new myclass[10](1,2); // create 10 myclasses
}
===========================================
Now this should be fairly straight forward:
We create a int, initialise it to 5, and point first to it.
We create an array of ints, initialise all to 5, and point second to it.
We create a myclass, with initialisation (1,2), and point one to it.
We create an array of myclasses, initialise all to (1,2), and point two to it.
Now, if I compile this using gcc (ver. 2.7.2.[12]) then all is OK.
Also, to prove that it's doing what I want, chucking in some printf's
shows that the initialisation is being handled correctly for both int's
and myclass's.
I recently upgraded gcc/g++ on my Debian/Linux machine to egcs. On
it, compilation now fails with:
>g++ crash.cc
crash.cc: In function `int main(...)':
crash.cc:16: no matching function for call to `myclass::myclass (int)'
crash.cc:7: candidates are: myclass::myclass(const myclass &)
crash.cc:5: myclass::myclass(int, int)
>g++ -v
Reading specs from /usr/lib/gcc-lib/i486-linux/egcs-2.90.28/specs
gcc version egcs-2.90.28 980423 (egcs-1.0.3 prerelease)
>
It compiles cleanly with "-Wall -pedantic -ansi" on the older gcc's
(ignoring the "unused variable" comments). However on the same problem
machine, egcs reports:
>g++ -Wall -pedantic -ansi crash.cc
crash.cc: In function `int main()':
crash.cc:13: warning: initialization in array new
crash.cc:16: warning: initialization in array new
crash.cc:16: no matching function for call to `myclass::myclass (int)'
crash.cc:7: candidates are: myclass::myclass(const myclass &)
crash.cc:5: myclass::myclass(int, int)
crash.cc:16: warning: unused variable `class myclass * two'
crash.cc:15: warning: unused variable `class myclass * one'
crash.cc:13: warning: unused variable `int * second'
crash.cc:12: warning: unused variable `int * first'
>
Have they changed the standard recently concerning initialising arrays ?
Egcs whinges, but still seems to accept it - if the myclass lines are
ommitted, then it compiles and runs correctly (well adding in some
printf's shows that it is doing the initialisation of second
correctly).
Or am I just missing something obvious ?
Any theories appreciated.
Cheers,
Craig.
----------------------- HUMBUG General List --------------------------------
echo "unsubscribe general" | mail majordomo at humbug.org.au # To Unsubscribe
More information about the General
mailing list