https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84009
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:66455591fac1e80b5acc615598cbf556d565e080 commit r16-2046-g66455591fac1e80b5acc615598cbf556d565e080 Author: Jakub Jelinek <ja...@redhat.com> Date: Mon Jul 7 09:17:34 2025 +0200 c++: Pedwarn on invalid decl specifiers for for-range-declaration [PR84009] https://eel.is/c++draft/stmt.ranged#2 says that in for-range-declaration only type-specifier or constexpr can appear. As the following testcases show, we've emitted some diagnostics in most cases, but not for static/thread_local (the patch handles __thread too) and register in the non-sb case. For extern there was an error that it is both extern and has an initializer (again, non-sb only, sb errors on extern). The following patch diagnoses those cases with pedwarn. I've used for-range-declaration in the diagnostics wording (there was already a case of that for the typedef), so that in the future we don't need to differentiate it between range for and expansion statements. 2025-07-07 Jakub Jelinek <ja...@redhat.com> PR c++/84009 * parser.cc (cp_parser_decomposition_declaration): Pedwarn on thread_local, __thread or static in decl_specifiers for for-range-declaration. (cp_parser_init_declarator): Likewise, and also for extern or register. * g++.dg/cpp0x/range-for40.C: New test. * g++.dg/cpp0x/range-for41.C: New test. * g++.dg/cpp0x/range-for42.C: New test. * g++.dg/cpp0x/range-for43.C: New test.