Jumping across initializers is forbidden, and this DR clarifies that that applies to initializers in init-statements too. We already detect this case, so I'm adding this test and marking the DR as resolved.
Tested on x86_64-linux, applying to trunk. 2019-09-21 Marek Polacek <pola...@redhat.com> DR 2345 - Jumping across initializers in init-statements and conditions. * g++.dg/cpp1z/init-statement10.C: New test. diff --git gcc/testsuite/g++.dg/cpp1z/init-statement10.C gcc/testsuite/g++.dg/cpp1z/init-statement10.C new file mode 100644 index 00000000000..d13d135dab1 --- /dev/null +++ gcc/testsuite/g++.dg/cpp1z/init-statement10.C @@ -0,0 +1,14 @@ +// DR 2345 - Jumping across initializers in init-statements and conditions. +// { dg-do compile { target c++17 } } + +int +fn () +{ + goto X; + if (int i = 42; i == 42) + { +X: // { dg-error "jump to label" } + return i; + } + return -1; +}