Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destructors are not called when jumping out of a scope #348

Open
bcardosolopes opened this issue Dec 7, 2023 · 0 comments
Open

Destructors are not called when jumping out of a scope #348

bcardosolopes opened this issue Dec 7, 2023 · 0 comments
Assignees

Comments

@bcardosolopes
Copy link
Member

          The original test program now works for me.  Destructors are called when falling off the end of a scope.  But destructors are not called when jumping out of a scope.  This program is missing some destructor calls.  Should I open a new issue for this, or reopen this one?
extern "C" int printf(char const*, ...);
struct A {
  A() { printf("++A\n"); }
  A(int n) { printf("++A(%d)\n", n); }
  ~A() { printf("--A\n"); }
};
void test(int x) {
  printf("test(%d)\n", x);
  A a;
  if (x == 1) return;
  {
    A b(3);
    if (x == 2) return;
  }
  if (x == 3) return;
}
int main() {
  test(1);
  test(2);
  test(3);
  test(4);
}

Originally posted by @dkolsen-pgi in #322 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant