From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5C7AF3857C7D; Wed, 6 Jul 2022 19:40:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C7AF3857C7D From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/53431] C++ preprocessor ignores #pragma GCC diagnostic Date: Wed, 06 Jul 2022 19:40:12 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.7.0 X-Bugzilla-Keywords: diagnostic, documentation, patch X-Bugzilla-Severity: minor X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Jul 2022 19:40:13 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D53431 --- Comment #51 from CVS Commits --- The master branch has been updated by Lewis Hyatt : https://gcc.gnu.org/g:e46f4d7430c5210465791603735ab219ef263c51 commit r13-1544-ge46f4d7430c5210465791603735ab219ef263c51 Author: Lewis Hyatt Date: Tue Jul 5 17:15:28 2022 -0400 diagnostics: Honor #pragma GCC diagnostic in the preprocessor [PR53431] As discussed on PR c++/53431, currently, "#pragma GCC diagnostic" does not always take effect for diagnostics generated by libcpp. The reason is that libcpp itself does not interpret this pragma and only sends it = on to the frontend, hence the pragma is only honored if the frontend arranges for it. The C frontend does process the pragma immediately (more or less) after seeing the token, so things work fine there. The PR points out that it doesn't work for C++, because the C++ frontend doesn't handle anything until it has read all the tokens from libcpp. The underlying problem is not C++-specific, though, and for instance, gcc -E has the same issue. This commit fixes the PR by adding the concept of an early pragma handl= er that can be registered by frontends, which gives them a chance to process diagnostic pragmas from libcpp before it is too late for them to take effect. The C++ and preprocess-only frontends are modified to use early pragmas and correct the behavior. gcc/c-family/ChangeLog: PR preprocessor/53920 PR c++/53431 * c-common.cc (c_option_is_from_cpp_diagnostics): New function. * c-common.h (c_option_is_from_cpp_diagnostics): Declare. (c_pp_stream_token): Declare. * c-ppoutput.cc (init_pp_output): Refactor logic about skipping pragmas to... (should_output_pragmas): ...here. New function. (token_streamer::stream): Support handling early pragmas. (do_line_change): Likewise. (c_pp_stream_token): New function. * c-pragma.cc (struct pragma_diagnostic_data): New helper class. (pragma_diagnostic_lex_normal): New function. Moved logic for interpreting GCC diagnostic pragmas here. (pragma_diagnostic_lex_pp): New function for parsing diagnostic pragmas directly from libcpp. (handle_pragma_diagnostic): Refactor into helper function... (handle_pragma_diagnostic_impl): ...here. New function. (handle_pragma_diagnostic_early): New function. (handle_pragma_diagnostic_early_pp): New function. (struct pragma_ns_name): Renamed to... (struct pragma_pp_data): ...this. Add new "early_handler" memb= er. (c_register_pragma_1): Support early pragmas in the preprocesso= r. (c_register_pragma_with_early_handler): New function. (c_register_pragma): Support the new early handlers in struct internal_pragma_handler. (c_register_pragma_with_data): Likewise. (c_register_pragma_with_expansion): Likewise. (c_register_pragma_with_expansion_and_data): Likewise. (c_invoke_early_pragma_handler): New function. (c_pp_invoke_early_pragma_handler): New function. (init_pragma): Add early pragma support for diagnostic pragmas. * c-pragma.h (struct internal_pragma_handler): Add new early handler members. (c_register_pragma_with_early_handler): Declare. (c_invoke_early_pragma_handler): Declare. (c_pp_invoke_early_pragma_handler): Declare. gcc/cp/ChangeLog: PR c++/53431 * parser.cc (cp_parser_pragma_kind): Move earlier in the file. (cp_lexer_handle_early_pragma): New function. (cp_lexer_new_main): Support parsing and handling early pragmas. (c_parse_file): Adapt to changes in cp_lexer_new_main. gcc/testsuite/ChangeLog: PR preprocessor/53920 PR c++/53431 * c-c++-common/pragma-diag-11.c: New test. * c-c++-common/pragma-diag-12.c: New test. * c-c++-common/pragma-diag-13.c: New test.=