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 not called inside for loop #1139

Open
smeenai opened this issue Nov 19, 2024 · 0 comments
Open

Destructors not called inside for loop #1139

smeenai opened this issue Nov 19, 2024 · 0 comments

Comments

@smeenai
Copy link
Collaborator

smeenai commented Nov 19, 2024

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.

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