This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/37722] New: destructors not called on computed goto
- From: "cburger at sunysb dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 2 Oct 2008 20:45:00 -0000
- Subject: [Bug c++/37722] New: destructors not called on computed goto
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
#include <iostream>
struct foo {
foo() { std::cout << "foo constructed\n"; }
~foo() { std::cout << "foo destructed\n"; }
};
enum opcode { NOP, FOO, DONE };
void exec0(const opcode* o) {
loop: switch (*o) {
case NOP: ++o; goto loop;
case FOO: { foo f; ++o; goto loop; } // f destructed
case DONE: return;
}
}
void exec1(const opcode* o) {
static void* label[] = { &&NOP, &&FOO, &&DONE };
goto *label[*o];
NOP: ++o; goto *label[*o];
FOO: { foo f; ++o; goto *label[*o]; } // f not destructed
// FOO: { foo f; ++o; } goto *label[*o]; // work-around
DONE: return;
}
int main() {
const opcode program[] = { NOP, FOO, NOP, NOP, DONE };
exec0(program);
exec1(program);
return 0;
}
Output:
foo constructed
foo destructed
foo constructed
Tested with: 4.3.2, 4.2.4, 4.1.3, 3.4.6
Optimization level makes no difference.
Intel icpc 10.1, 9.1 show the same problem.
--
Summary: destructors not called on computed goto
Product: gcc
Version: 4.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: cburger at sunysb dot edu
GCC build triplet: x86_64-linux-gnu
GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37722