Bug 80472 - cannot use push/pop with #pragma GCC diagnostic warning "-Wsystem-headers"
Summary: cannot use push/pop with #pragma GCC diagnostic warning "-Wsystem-headers"
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.3.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, easyhack
Depends on:
Blocks: 58876 70692 87614 69769
  Show dependency treegraph
 
Reported: 2017-04-20 12:15 UTC by Jonathan Wakely
Modified: 2018-10-15 16:09 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-04-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2017-04-20 12:15:56 UTC
Given the following header:

#pragma GCC system_header
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wsystem-headers"
// want warnings here despite being in a system header
#pragma GCC diagnostic pop
// But don't want warnings here
int missing_return() { }


A file including it will warn with -Wreturn-type (or -Wall):

In file included from dep.cc:1:0:
dep.h: In function ‘int missing_return()’:
dep.h:8:24: warning: no return statement in function returning non-void [-Wreturn-type]
 int missing_return() { }
                        ^

The warning should be disabled again by the "pop", but -Wsystem-headers stays active once enabled.

This makes it very difficult for libstdc++ to selectively enable important warnings, e.g. Bug 58876
Comment 1 Marek Polacek 2017-04-20 12:28:21 UTC
Confirmed :(.
Comment 2 Manuel López-Ibáñez 2017-08-19 12:10:59 UTC
Currently, the macro controlling this only looks at the state of the option:

/* Returns nonzero if warnings should be emitted.  */
#define diagnostic_report_warnings_p(DC, LOC)                           \
  (!(DC)->dc_inhibit_warnings                                           \
   && !(in_system_header_at (LOC) && !(DC)->dc_warn_system_headers))

It needs to look at the classification_history like diagnostic_report_diagnostic() does.
Comment 3 Manuel López-Ibáñez 2017-08-19 12:20:05 UTC
It seems pretty straight-forward:

1. Abstract out the check for classification_history.

2. Create a function diagnostic_report_warnings_p that checks the classification history of Wsystem-headers in addition to the option value.

Not that -Wsystem-headers is not a typical warning option, so more work would be needed to have

#pragma GCC diagnostic error "-Wsystem-headers"

give errors instead  of warnings

or

-Werror
#pragma GCC diagnostic warning "-Wsystem-headers"

give warnings instead of errors. But that seems less important to fix.