Bug 106423 - -Wc++20-compat diagnostics not suppressed by #pragma GCC diagnostic ignored
Summary: -Wc++20-compat diagnostics not suppressed by #pragma GCC diagnostic ignored
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: 13.0
Assignee: Not yet assigned to anyone
URL: https://gcc.gnu.org/pipermail/gcc-pat...
Keywords: diagnostic, patch
Depends on:
Reported: 2022-07-24 03:32 UTC by Tom Honermann
Modified: 2022-08-22 11:02 UTC (History)
3 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2022-08-09 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Tom Honermann 2022-07-24 03:32:39 UTC
As demonstrated at https://godbolt.org/z/GoTqPTcM3, use of gcc's '#pragma GCC diagnostic ignored "-Wc++20-compat"' directive fails to suppress -Wc++20-compat enabled diagnostics. gcc versions 10 and up are affected.

$ cat t.cpp
#pragma GCC diagnostic ignored "-Wc++20-compat"
int constinit;

$ gcc -c -std=c++17 -Wc++20-compat t.cpp
t.cpp:2:5: warning: identifier ‘constinit’ is a keyword in C++20 [-Wc++20-compat]
    2 | int constinit;
      |     ^~~~~~~~~
Comment 1 Tom Honermann 2022-07-24 04:41:47 UTC
A patch for this issue was submitted to the gcc-patches mailing list and is available at https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598736.html.
Comment 2 CVS Commits 2022-08-16 19:15:46 UTC
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:


commit r13-2081-g60468d6cd46a3bd3afe8ff856f82afcd4c65a217
Author: Tom Honermann <tom@honermann.net>
Date:   Mon Aug 1 14:49:00 2022 -0400

    c++: Fix pragma suppression of -Wc++20-compat diagnostics [PR106423]
    Gcc's '#pragma GCC diagnostic' directives are processed in "early mode"
    (see handle_pragma_diagnostic_early) for the C++ frontend and, as such,
    require that the target diagnostic option be enabled for the preprocessor
    (see c_option_is_from_cpp_diagnostics).  This change modifies the
    -Wc++20-compat option definition to register it as a preprocessor option
    so that its associated diagnostics can be suppressed.  The changes also
    implicitly disable the option in C++20 and later modes.  These changes
    are consistent with the definition of the -Wc++11-compat option.
    This support is motivated by the need to suppress the following diagnostic
    otherwise issued in C++17 and earlier modes due to the char8_t typedef
    present in the uchar.h header file in glibc 2.36.
      warning: identifier âchar8_tâ is a keyword in C++20 [-Wc++20-compat]
    Tests are added to validate suppression of both -Wc++11-compat and
    -Wc++20-compat related diagnostics (fixes were only needed for the C++20
            PR c++/106423
            * c-opts.cc (c_common_post_options): Disable -Wc++20-compat
            diagnostics in C++20 and later.
            * c.opt (Wc++20-compat): Enable hooks for the preprocessor.
            * parser.cc (cp_lexer_saving_tokens): Add comment regarding
            diagnostic requirements.
            * g++.dg/cpp0x/keywords2.C: New test.
            * g++.dg/cpp2a/keywords2.C: New test.
            * include/cpplib.h (cpp_warning_reason): Add CPP_W_CXX20_COMPAT.
            * init.cc (cpp_create_reader): Add cpp_warn_cxx20_compat.
Comment 3 Tom Honermann 2022-08-17 16:35:48 UTC
I believe this issue can be resolved as fixed via commit 60468d6cd46a3bd3afe8ff856f82afcd4c65a217 for the gcc 13 release.
Comment 4 Ville Voutilainen 2022-08-17 16:39:00 UTC
(In reply to Tom Honermann from comment #3)
> I believe this issue can be resolved as fixed via commit
> 60468d6cd46a3bd3afe8ff856f82afcd4c65a217 for the gcc 13 release.

Yes, it's normal procedure that the bz will be closed as fixed once the patches have been merged, it's just a separate step.
Comment 5 Jonathan Wakely 2022-08-22 11:02:41 UTC
Fixed, thanks.