This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Possible C++ bug: construction/destruction of global objects
- From: Evan Lavelle <eml at riverside-machines dot com>
- To: gcc-bugs <gcc-bugs at gcc dot gnu dot org>
- Date: Tue, 11 Mar 2003 20:40:05 +0000
- Subject: Possible C++ bug: construction/destruction of global objects
- Organization: Riverside Machines Ltd.
Is this a bug? Basically, if I declare more than one object of type
'wibble' at global scope (ie. 'foo1' and 'foo2' below), and 'wibble' has
a string constructor parameter, and the 'wibble' constructor calls
exit(), then I get a SIGSEGV during the exit(). This happens before
main() is called. Note that the code works (ie. the exit() completes
without a problem) if I declare only one 'wibble' object.
I'm on 2.96, x86, RH7.2.
Thanks.
-------------------------------------------------------------------------
#include <string>
#include <cstdlib>
struct wibble {
string name;
wibble(string n) : name(n) {
cout << "exiting:" << endl;
exit(1); // get a SIGSEGV here
}
};
wibble foo1("foo1");
wibble foo2("foo2"); // commenting this out solves the problem
int main() {
cout << "Shouldn't get this far" << endl;
}