goto
or switch
can jump over a declaration-statement given that it has no initializer and the construction is trivial — and that the object is also trivially destructible.
What's the rationale for the constraint on the destructor?
struct trivial {
trivial() = default;
~ trivial() = default;
};
struct semi_trivial {
semi_trivial() = default;
~ semi_trivial() noexcept { do_something(); }
};
void foo() {
goto good_label; // OK
trivial foo;
good_label:
goto bad_label; // Error: this goto statement
semi_trivial bar; // cannot jump over this declaration.
bad_label:
std::cout << "hi\n";
}