Re: VC++2008: STL access violation depending on runtime library being used -- bug or undefined behavior?
"Alan Carre" <alan@twilightgames.com> wrote in message
news:%23TOIPUj4IHA.4908@TK2MSFTNGP04.phx.gbl
Sorry, I wrote my example backwards and quickly and incorrectly.
I guess you'll have to trust me... It just so happens I had to unwind
one of these mixed up sequences a couple days ago and I was trying to
reproduce the sequence in my head and failed miserably ;-)
I fully believe that the program does indeed crash the way the OP
describes. I have no reason to doubt his statement, nor yours.
However, I disagree with your claim that there's no bug in the STL
implementation, but the program itself is at fault. As far as I can
tell, the program is perfectly valid and C++-standard-conformant, and
the blame for its misbehavior lies squarely on the implementation.
I think all you need are 2 "static function" objects to cause a crash.
Something like...
class Crasher
{
static ComplicatedObject& GetObject1() {static ComplicatedObject
obj; return obj;}
public:
Crasher() {GetObject1();}
~Crasher() {GetObject1();}
}
Crasher& func()
{
static Crasher crasher;
return crasher;
}
And that should do it!
Of course. But I fail to see how this is relevant to the original
program we are discussing. That program declares only one global object,
and doesn't reference any others.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925