egcs bug?

Charles Calkins calkinsc@www.protospace.com
Mon May 17 11:50:00 GMT 1999


	Greetings

	I have come across some odd behaviour from egcs and wanted to report
it - I'm afraid I do not have access to the absolute newest build of egcs to
test, but 1.1 shows an oddity.  

The system and compilation flags:

[calkinsc@psfv ~]$ egcs -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.57/specs
gcc version egcs-2.91.57 19980901 (egcs-1.1 release)

[calkinsc@psfv ~]$ ls -l /usr/lib/libstdc++*
-rw-r--r--   1 root     root      1796160 May 13 13:37 /usr/lib/libstdc++.a
lrwxrwxrwx   1 root     root           18 Mar 26 08:23 /usr/lib/libstdc++.so.2.8 -> libstdc++.so.2.8.0
-r-xr-xr-x   1 root     root       375773 Oct 14  1998 /usr/lib/libstdc++.so.2.8.0
lrwxrwxrwx   1 root     root           18 May 11 13:22 /usr/lib/libstdc++.so.2.9 -> libstdc++.so.2.9.0
-r-xr-xr-x   1 root     root       261396 Sep  4  1998 /usr/lib/libstdc++.so.2.9.0

[calkinsc@psfv ~]$ uname -a
Linux psfv.protospace.com 2.0.36 #1 Tue Oct 13 22:17:11 EDT 1998 i586 unknown

[calkinsc@psfv ~]$ g++ -o t2 t2.cc


The program:

#include <iostream>
#include <vector>

class A {
  int i;
public:
  A() : i(0) { cout << "A() == " << this << endl; }
  A(int _i) : i(_i) { cout << "A(" << i << ") == " << this << endl; }
  ~A() { cout << "~A(" << i << ") == " << this << endl; }
  A(const A &a) : i(a.i) { cout << "A(A(" << a.i << ")) == " << this << endl;
}
  A operator=(const A &a) { i=a.i; cout << "=A(" << a.i << ") == " << this <<
endl; }
};


main() {
  cout << "construct v" << endl;
  vector<A> v;

  cout << "resize v" << endl;
  v.resize(2);

  /*
  cout << "construct A(20237)" << endl;
  A(20237);
  */
  cout << "assign A(1)" << endl;
  v[0]=A(1);

  cout << "exit" << endl;
}



The execution:

construct v
resize v
A() == 0xbffffd74
A(A(0)) == 0x80597a0
A(A(0)) == 0x80597a4
~A(0) == 0xbffffd74
assign A(1)
A(1) == 0xbffffd8c
=A(1) == 0x80597a0
~A(1074022329) == 0xbffffd90
~A(1) == 0xbffffd8c
exit
~A(1) == 0x80597a0
~A(0) == 0x80597a4


	Note the destruction of A where A's variable i appears to be
uninitialized, but if C++ constructors are followed, there is no way for i to
not be initialized to at least 0.  If I uncomment the lines regarding A(20237)
I get:

construct v
resize v
A() == 0xbffffd74
A(A(0)) == 0x8059810
A(A(0)) == 0x8059814
~A(0) == 0xbffffd74
construct A(20237)
A(20237) == 0xbffffd90
~A(20237) == 0xbffffd90
assign A(1)
A(1) == 0xbffffd8c
=A(1) == 0x8059810
~A(20237) == 0xbffffd90
~A(1) == 0xbffffd8c
exit
~A(1) == 0x8059810
~A(0) == 0x8059814

	Now its even more interesting, as not only does A(20237) use the same
memory location which the offending ~A(1074022329) does, it shows that
A(20237)'s destructor is called twice. 

	If there is any more information I can provide to be of assistance,
please let me know.

							Charles
--
Charles Calkins				calkinsc@protospace.com
Senior Software Developer 		http://www.protospace.com/~calkinsc
ProtoSpace Corporation			St. Louis, MO



More information about the Gcc-bugs mailing list