This is the mail archive of the gcc@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]

Bug: static object inside a function






This problem was reported in Windows Developer Journal.
Originally the bug reported for MSVC but EGCS 1.1 (mingw32 version)
has this bug too.

consider the following function:

XX* f()
{
   static XX x;
   return &xx;
}

suppose the constructor of XX throws. then in the next call to f() the XX
object
should be constructed once again (there is no skip over the static init)
This is not the case in EGCS 1.1 - the object is marked as constructed
even if the first initialization throws.

Here is a small program that demonstrates the bug:


#include <iostream>

struct X
{
   X() { throw 1; }
};

X& getX()
{
   static X x;
   return x;
}

int main()
{
   using namespace std;

   try {
      getX();
      cout << "*** BUG ***\n";
   }
   catch(...) {
      cout << "OK\n";
   }

   try {
      getX();
      cout << "*** BUG ***\n";
   }
   catch(...) {
      cout << "OK\n";
   }
}


Eyal.




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