Goto out of a block: do destructors get called?
问题 Consider the following code: void foo() { { CSomeClass bar; // Some code here... goto label; // and here... } label: // and here... } Will the destructor of bar be called ? 回答1: The C++ Standard says: On exit from a scope (however accomplished), destructors (12.4) are called for all constructed objects with automatic storage duration (3.7.2) (named objects or temporaries) that are declared in that scope, in the reverse order of their declaration. So the answer is "yes". 回答2: Yes, they will be