clangir icon indicating copy to clipboard operation
clangir copied to clipboard

Destructors are not called when jumping out of a scope

Open bcardosolopes opened this issue 1 year ago • 0 comments

          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 https://github.com/llvm/clangir/issues/322#issuecomment-1843977097

bcardosolopes avatar Dec 07 '23 01:12 bcardosolopes