[PATCH] PR18327: -Wsystem-headers introduces build errors

Richard Smith richard at metafoo.co.uk
Mon Jan 6 13:47:02 PST 2014

On Mon, Jan 6, 2014 at 1:02 PM, Alp Toker <alp at nuanti.com> wrote:

> On 06/01/2014 19:27, Richard Smith wrote:
>> We need to figure out what -Wsystem-headers should do in some corner
>> cases. In particular:
>>  * If I -Werror= a warning, and I have -Wsystem-headers, and the warning
>> occurs in a system header, what should happen?
>>  * If I use -Werror=system-headers, and a DefaultError warning (like
>> -Winvalid-constexpr) is issued in a system header, what should happen?
>>  * If I use -Werror=system-headers, and a (non-promoted-to-error) warning
>> occurs in a system header, what should happen?
>>  * If I use -Werror globally, and I have -Wsystem-headers enabled, and a
>> warning is produced in a system header, what should happen?
>> One possible approach would be to set the apparent severity of
>> diagnostics in system headers to max(warning severity, -Wsystem-headers
>> severity). So -Wsystem-headers would allow warnings (but not errors) to be
>> produced in system headers, and -Werror=system-headers would also allow
>> errors to be produced in system headers.
> Getting -W[no-]error=system-headers play ball sounds like it'd need work
> given what a special case it is, with limited use cases for all that
> flexibility. My motivation here was just to make -Wsystem-headers safe to
> enable at all.

Right, I had been assuming that -Werror=system-headers already existed. But
it appears that -Wsystem-headers is even more special-case than I'd
thought, and doesn't act like a warning flag at all. =(

I suspect -Wsystem-headers -Werror should treat all header warnings as
> errors though. Think we have a workable solution if I update the proposed
> patch with that case?
> -      // Ensure that -Wsystem-headers never introduces errors due to
> mapping.
> -      Result = DiagnosticIDs::Warning;
> +      // Ensure that -Wsystem-headers doesn't introduce errors due to
> mapping.
> +      if (!Diag.WarningsAsErrors)
> +        Result = DiagnosticIDs::Warning;

If we go this way, I think we also would want -Werror=foo -Wsystem-headers
to produce diagnostic 'foo' as an error in system headers.

Another would be your current patch (never produce errors in system
>> headers).
> Just to clarify, the patch only prevents new errors being introduced by
> -Wsystem-headers that would not otherwise fire. It doesn't suppress any
> other errors that usually fire in system headers.

Sorry, I was unclear here; I meant "never emit Warning diagnostics as
errors in system headers".

>> Another would be to treat all warnings in system headers as if they're
>> controlled by the -Wsystem-headers flag (so -Werror=system-headers would
>> promote them all to errors, as would -Werror -Wsystem-headers).
> Would that need early checks on the warning location to see if it's in
> system headers? The check is described as expensive so I've left it until
> just before emission.

No, I meant that you'd still perform the check in the same place; only
warnings that would be displayed outside a system header would get the
additional check. But I don't think this option is the right approach; it
doesn't seem very useful from a user's point of view.

>> Maybe there's another, better, option.
One other option would be to make no change. Ultimately, what I was trying
to drive towards with my earlier questions was, what is the semantic model
for -Wsystem-headers? What does a user expect it to mean?

One view on this is simply: -Wsystem-headers means "don't give system
headers special treatment when emitting diagnostics". That would seem to
make perfect sense to people developing system headers, and is our current
behavior. What is the use case that leads to enabling -Wsystem-headers but
not wanting that to lead to errors? PR18327 doesn't make that obvious.

> Thoughts?
>> On Sun Dec 29 2013 at 7:01:45 AM, Alp Toker <alp at nuanti.com <mailto:
>> alp at nuanti.com>> wrote:
>>     The -Wsystem-headers option was enabling warnings that got upgraded to
>>     errors
>>     through mappings like DefaultError. In a normal build these errors
>>     are fully
>>     suppressed.
>>     This patch makes -Wsystem-headers consistent with ordinary
>>     behaviour by
>>     restoring mapped errors in system headers to warnings, ensuring
>>     that the
>>     option
>>     can never cause build failures.
>>     The test case extends existing checks added in r169689 / PR14550.
>>     Alp.
>>     --
>>     http://www.nuanti.com
>>     the browser experts
> --
> http://www.nuanti.com
> the browser experts
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140106/1388f2fa/attachment.html>

More information about the cfe-commits mailing list