Bug 53920 - "gcc -E" does not honor #pragma GCC diagnostic ignored "-Wunused-macro"
Summary: "gcc -E" does not honor #pragma GCC diagnostic ignored "-Wunused-macro"
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 4.7.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, easyhack
Depends on:
Blocks:
 
Reported: 2012-07-10 17:50 UTC by Samuel Bronson
Modified: 2015-03-27 15:30 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-11-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Samuel Bronson 2012-07-10 17:50:08 UTC
iMac:gcc-bugs user$ cat cpp-pragma-GCC-diagnostic.c

#pragma GCC diagnostic ignored "-Wunused-macros"
#define FOO

iMac:gcc-bugs user$ gcc-fsf-4.7 -Wunused-macros cpp-pragma-GCC-diagnostic.c -E
# 1 "cpp-pragma-GCC-diagnostic.c"
# 1 "<command-line>"
# 1 "cpp-pragma-GCC-diagnostic.c"

#pragma GCC diagnostic ignored "-Wunused-macros"
cpp-pragma-GCC-diagnostic.c:3:0: warning: macro "FOO" is not used [-Wunused-macros]
iMac:gcc-bugs user$ gcc-fsf-4.7 --version
gcc-fsf-4.7 (GCC) 4.7.1
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Comment 1 Samuel Bronson 2012-07-10 19:07:26 UTC
Oh, I suppose I should mention that I ran into this because I was using ccache to compile Emacs with --enable-gcc-warnings, and by default ccache runs the preprocessor and the compiler in separate passes (so that it can skip the compilation proper if it has cached output for a given preprocessor output), and then pastes together the diagnostic output from the two passes.

(Thankfully, setting the environment variable CCACHE_CPP2 causes ccache to throw out the preprocessor output after hashing, which is a quite effective workaround for this sort of thing, though preprocessing the source twice does make things a bit slower on cache misses.)
Comment 2 Manuel López-Ibáñez 2013-11-16 20:41:39 UTC
The C FE normally preprocesses and parses concurrently. But -E (only preprocessing) is handled by a different function in c-ppoutput.c(scan_translation_unit), which does not handle pragma diagnostics. So someone would need to add that handling there. Probably not difficult. I think one just needs to call c_invoke_pragma handler when a pragma diagnostic is detected, but someone has to try and flush out the details. If you need help just ask.