is this a string bug?
Joe Buck
jbuck@synopsys.com
Tue Oct 28 20:32:00 GMT 1997
> In chapter 5 of the new Stroustrup edition there is the program
> shown below. It produces:
....
It appears that the problem is with the line
> Pair p = {s, 0};
I think the code to handle this was originally put in as a GNU extension
to C; also I'm fairly sure that this form is a recent addition to C++.
Right? (Because of this I had always thought of this form as a GNU
extension and so always avoided it).
Anyway, it seems to be malfunctioning in that it appears that a shallow
copy is being done to initialize the string field of p rather than using
the copy constructor.
If you write a constructor for Pair, and replace that line with
Pair p(s,0);
the program will work correctly (Pair has to also have a default
constructor). So it is not a bug in the string class, but in the
handling of aggregate initialization.
More information about the Gcc
mailing list