This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Possible C++ bug: construction/destruction of global objects


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;
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]