[Bug middle-end/37722] destructors not called on computed goto

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Jan 3 17:33:02 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37722

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think computed gotos are similar to longjmp here, the compiler doesn't know
where exactly the jump will go to and so which variables should be destructed
on a particular computed goto at runtime.
For normal gotos, the compiler knows which scopes will be left and can arrange
for those destructors to be run, and similarly which scopes will be entered and
can complain if construction of some vars is jumped over.
For longjmp, C++ documents it as undefined behavior:
https://eel.is/c++draft/csetjmp.syn#2
I'm afraid for computed gotos all we can do is just document something similar
for leaving the C++ scopes (and C with cleanup attribute) with computed gotos
and  similarly document that any crossed initializations of variables are
undefined behavior (normal gotos crossing initialization are errors in C++ but
not in C).


More information about the Gcc-bugs mailing list