https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103896
Bug ID: 103896
Summary: Label as value: object destructor is not called
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: fchelnokov at gmail dot com
Target Milestone: ---
When executing this program:
```
#include <iostream>
struct NonTrivial {
NonTrivial() { std::cout << "ctor "; }
~NonTrivial() { std::cout << "dtor "; }
};
int main() {
int i = 0;
start:
NonTrivial object;
goto *((i++ == 0) ? &&start : &&end);
end:;
}
```
GCC prints: `ctor ctor dtor` meaning that the object was constructed twice but
destructed only once, which looks as a bug. Demo:
https://gcc.godbolt.org/z/aWdYx8ox4
Related discussion: https://stackoverflow.com/q/60812880/7325599