switch is just a fancy goto, right.

C++17 §9.7/3

" A program that jumps 91 from a point where a variable with automatic storage duration is not in scope to a point where it is in scope is ill-formed unless the variable has scalar type, class type with a trivial default constructor and a trivial destructor, a cv-qualified version of one of these types, or an array of one of the preceding types and is declared without an initializer.

The way I read that is that the “and is declared without an initializer” applies to all the possibilities, so that your code is ill-formed (invalid).

However, while Visual C++ 2017 emits a warning about it, MinGW g++ 7.2 with -Wall -pedantic compilers that code cleanly. :(

/r/cpp_questions Thread