]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Pedwarn on invalid decl specifiers for for-range-declaration [PR84009]
authorJakub Jelinek <jakub@redhat.com>
Mon, 7 Jul 2025 07:17:34 +0000 (09:17 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 7 Jul 2025 07:25:15 +0000 (09:25 +0200)
commit66455591fac1e80b5acc615598cbf556d565e080
treed43f2c38aba059b27a4770c4ef7ed1b4765dcfed
parent849878d4fd40ad4ac2bff9a7bfe50176051d7176
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  <jakub@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.
gcc/cp/parser.cc
gcc/testsuite/g++.dg/cpp0x/range-for40.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/range-for41.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/range-for42.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/range-for43.C [new file with mode: 0644]