public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/37722]  New: destructors not called on computed goto
@ 2008-10-02 20:46 cburger at sunysb dot edu
  2008-10-02 21:23 ` [Bug middle-end/37722] " pinskia at gcc dot gnu dot org
  2009-05-09  8:17 ` scovich at gmail dot com
  0 siblings, 2 replies; 9+ messages in thread
From: cburger at sunysb dot edu @ 2008-10-02 20:46 UTC (permalink / raw)
  To: gcc-bugs

#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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-01-03  4:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-37722-4@http.gcc.gnu.org/bugzilla/>
2013-01-11 14:52 ` [Bug middle-end/37722] destructors not called on computed goto timo.kreuzer at reactos dot org
2022-01-03 12:00 ` pinskia at gcc dot gnu.org
2022-01-03 17:33 ` jakub at gcc dot gnu.org
2023-07-19 16:46 ` ndesaulniers at google dot com
2023-12-21  2:07 ` cvs-commit at gcc dot gnu.org
2023-12-21  2:08 ` jason at gcc dot gnu.org
2024-01-03  4:23 ` egallager at gcc dot gnu.org
2008-10-02 20:46 [Bug c++/37722] New: " cburger at sunysb dot edu
2008-10-02 21:23 ` [Bug middle-end/37722] " pinskia at gcc dot gnu dot org
2009-05-09  8:17 ` scovich at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).