https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121647
Bug ID: 121647 Summary: template for: can't contain case labels for surrounding switch Product: gcc Version: 16.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ivan.lazaric.gcc at gmail dot com Target Milestone: --- https://godbolt.org/z/9Tj9enaxK Code: ``` template<auto> void blah(); void use(int x){ switch (x){ template for (constexpr int y : {1,2,3}){ case y: { blah<y>(); break; } } default: break; } } ``` Compiled with flags: -std=c++26 -O3 (though -O3 shouldn't matter) This fails to compile with error: ``` <source>: In function 'void use(int)': <source>:8:18: error: jump to case label 8 | case y: { blah<y>(); break; } | ^ <source>:7:9: note: enters 'template for' statement 7 | template for (constexpr int y : {1,2,3}){ | ^~~~~~~~ <source>:7:37: warning: statement will never be executed [-Wswitch-unreachable] 7 | template for (constexpr int y : {1,2,3}){ | ^ ``` What I expected: I expected the code to compile, and be functionally equivalent to: ``` template<auto> void blah(); void use(int x){ switch (x){ case 1: { blah<1>(); break; } case 2: { blah<2>(); break; } case 3: { blah<3>(); break; } default: break; } } ``` Whether or not the standard supports my expectations I am unsure Just noting same code compiles with the experimental clang implementation: https://godbolt.org/z/snfG7qqKh