]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Make __extension__ silence -Wlong-long pedwarns/warnings [PR121133]
authorJakub Jelinek <jakub@redhat.com>
Wed, 30 Jul 2025 11:23:56 +0000 (13:23 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 30 Jul 2025 12:49:53 +0000 (14:49 +0200)
commit281a6a0a8b3b2fd7c07ad6e0bf8454d60d9d5034
treef33e8a6cc0e8c0d7f9badd15eda6e5f09e31f119
parent9a5a5e87ca6fa5087b8151816d90b734451e5bc4
c++: Make __extension__ silence -Wlong-long pedwarns/warnings [PR121133]

The PR13358 r0-92909 change changed the diagnostics on long long
in C++ (either with -std=c++98 or -Wlong-long), but unlike the
C FE we unfortunately warn even in the
__extension__ long long a;
etc. cases.  The C FE in that case in
disable_extension_diagnostics saves and clears not just
pedantic flag but also warn_long_long (and several others), while
C++ FE only temporarily disables pedantic.

The following patch makes it behave like the C FE in this regard,
though (__extension__ 1LL) still doesn't work because of the
separate lexing (and I must say I have no idea how to fix that).

Or do you prefer a solution closer to the C FE, cp_parser_extension_opt
saving the values into a bitfield and have another function to restore
the state (or use RAII)?

2025-07-30  Jakub Jelinek  <jakub@redhat.com>

PR c++/121133
* parser.cc (cp_parser_unary_expression): Adjust
cp_parser_extension_opt caller and restore warn_long_long.
(cp_parser_declaration): Likewise.
(cp_parser_block_declaration): Likewise.
(cp_parser_member_declaration): Likewise.
(cp_parser_extension_opt): Add SAVED_LONG_LONG argument,
save previous warn_long_long state into it and clear it
for __extension__.

* g++.dg/warn/pr121133-1.C: New test.
* g++.dg/warn/pr121133-2.C: New test.
* g++.dg/warn/pr121133-3.C: New test.
* g++.dg/warn/pr121133-4.C: New test.

(cherry picked from commit fac66b476afccac607dbd9b4e971a42a04666387)
gcc/cp/parser.cc
gcc/testsuite/g++.dg/warn/pr121133-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/pr121133-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/pr121133-3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/pr121133-4.C [new file with mode: 0644]