Possible Duplicate:
Goto out of a block: do destructors get called?
I know that goto operator both in C and C++ is useless in almost all situations, but i want to know the answer for this question only by interest, it has no practical meaning.
Does C++ standard guarantees that in such situations destructors of objects must be called properly?
#include <iostream>
class Foo
{
public:
Foo() { std::cout << "Foo::Foo() \n"; }
~Foo() { std::cout << "Foo::~Foo() \n"; }
};
int main()
{
{
std::size_t i = 0;
_1:
Foo instance;
if (!++i)
{
goto _1;
}
}
{
Foo instance;
goto _2;
}
_2:
;
}
http://liveworkspace.org/code/06031e6699c8fddda94b8594ccab1387
And what about other stange situations with goto and C++ RAII?
It would be really cool if you can post here the quotes from the C++ standard.