public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-53431-4-H7fxyRZSfi@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-53431-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431 --- Comment #51 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Lewis Hyatt <lhyatt@gcc.gnu.org>: https://gcc.gnu.org/g:e46f4d7430c5210465791603735ab219ef263c51 commit r13-1544-ge46f4d7430c5210465791603735ab219ef263c51 Author: Lewis Hyatt <lhyatt@gmail.com> 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 handler 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" member. (c_register_pragma_1): Support early pragmas in the preprocessor. (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.
next prev parent reply other threads:[~2022-07-06 19:40 UTC|newest] Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-05-21 8:03 [Bug c++/53431] New: C++ preprocessor ignores #pragma GCC diagnostic ignored "-Wundef" ml.lattuada at libero dot it 2013-02-17 17:04 ` [Bug c++/53431] " rainarchitect at gmail dot com 2013-03-03 4:10 ` markus at oberhumer dot com 2013-07-12 9:20 ` nomegenerico at email dot it 2013-11-16 18:13 ` rainarchitect at gmail dot com 2013-11-16 19:51 ` manu at gcc dot gnu.org 2013-11-16 20:23 ` manu at gcc dot gnu.org 2014-09-05 17:42 ` [Bug c++/53431] C++ preprocessor ignores #pragma GCC diagnostic manu at gcc dot gnu.org 2015-06-03 8:27 ` manu at gcc dot gnu.org 2015-07-20 9:38 ` manu at gcc dot gnu.org 2015-07-22 0:00 ` noloader at gmail dot com 2015-07-22 10:51 ` redi at gcc dot gnu.org 2015-07-22 11:24 ` noloader at gmail dot com 2015-07-23 10:34 ` noloader at gmail dot com 2015-07-23 10:47 ` redi at gcc dot gnu.org 2015-07-23 11:32 ` manu at gcc dot gnu.org 2015-07-23 13:20 ` manu at gcc dot gnu.org 2015-07-23 23:26 ` noloader at gmail dot com 2015-07-30 17:22 ` miyuki at gcc dot gnu.org 2021-02-27 11:24 ` noloader at gmail dot com 2021-06-03 12:04 ` redi at gcc dot gnu.org 2021-10-06 14:40 ` jakub at gcc dot gnu.org 2021-12-01 17:43 ` egallager at gcc dot gnu.org 2021-12-04 17:48 ` lhyatt at gcc dot gnu.org 2021-12-19 11:55 ` pinskia at gcc dot gnu.org 2021-12-19 19:50 ` manu at gcc dot gnu.org 2021-12-24 21:29 ` lhyatt at gcc dot gnu.org 2022-03-23 0:58 ` pinskia at gcc dot gnu.org 2022-05-25 13:38 ` lhyatt at gcc dot gnu.org 2022-06-29 16:08 ` lhyatt at gcc dot gnu.org 2022-07-06 19:40 ` cvs-commit at gcc dot gnu.org [this message] 2022-07-06 19:42 ` lhyatt at gcc dot gnu.org 2022-07-06 22:59 ` lhyatt at gcc dot gnu.org 2022-11-08 22:28 ` redi at gcc dot gnu.org 2022-11-09 0:05 ` markus at oberhumer dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-53431-4-H7fxyRZSfi@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).