Regular goto in C++ respects object lifetime - that is using goto to jump out of a block will run the destructors for the appropriate local variables.
start:
NonTrivial object;
if (again()) goto start; // will call object.~NonTrivial()
Is the same true when using the Labels as Values extension?
start:
NonTrivial object;
goto *(again() ? &&start : &&end);
end:
GCC happily accepts this code, but seems to ignore any effect goto might have on object's lifetime. Clang complains:
error: cannot jump from this indirect goto statement to one of its possible targets
note: possible target of indirect goto statement
note: jump exits scope of variable with non-trivial destructor
Look for calls to NonTrivial() and ~NonTrivial() in Compiler Explorer.
Which compiler behaves correctly? Is it even possible, in general, to support this kind of indirect branching and also correctly manage object lifetime and RAII?