c++ copy constructor bug

Benoit Hudson bhudson@ptolemy.arc.nasa.gov
Wed May 24 12:05:00 GMT 2000


I'm trying to get some code to interact between C and C++.  For some
reason, I was having trouble with my values being completely mangled
on linux (redhat 6.1) -- but not on Solaris 2.6.  I'm using gcc 2.95.2 on
both.  I also get the bug on linux with egcs-2.91.66 (the compiler packaged
with rh6.1).

I've reduced the problem to what's in the attached files.  To get the bug,
leave in the copy constructor for mystruct.  To avoid it, remove the copy
constructor.  The program should print [5,5] twice, but instead prints
garbage if the copy constructor is there.  When debugging, you'll notice
that there's no problem in main; but obviously the wrong values are passed
in to printMyStruct.

I've tried flags -g, -g -O2, and no flags; different garbage is printed
depending on optimization, but it's still garbage.


More information about the Gcc-bugs mailing list