This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Bug: static object inside a function
- To: egcs at cygnus dot com
- Subject: Bug: static object inside a function
- From: eyal dot ben-david at aks dot com
- Date: Tue, 6 Oct 1998 20:35:04 +0200
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.