clangir icon indicating copy to clipboard operation
clangir copied to clipboard

Destructors not called inside for loop

Open smeenai opened this issue 1 year ago • 1 comments

https://godbolt.org/z/bdqM4ccxf demonstrates the issue. For the following code:

#include <stdio.h>
struct S { ~S() { puts("~S"); } };
int main() {
    for (int i = 0; i < 4; i++) {
        S s;
    }
}

CIR calls the destructor at the end of the for loop (including when exiting it with a break) instead of inside it. This is kinda like the opposite of #348; in this case, the destructor is called when jumping out of a scope but not when exiting and resuming it normally.

smeenai avatar Nov 19 '24 05:11 smeenai

Yea, we have a list of other issues where we are missing dtors, if no one beats me to it, I'll do this one.

bcardosolopes avatar Nov 22 '24 20:11 bcardosolopes