Bug 95024 - want a way to turn off -Werror for a specific diagnostic but only emit an warning if it was turned on before hand
Summary: want a way to turn off -Werror for a specific diagnostic but only emit an war...
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 10.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2020-05-09 19:33 UTC by Alejandro Colomar
Modified: 2020-05-10 01:17 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alejandro Colomar 2020-05-09 19:33:40 UTC
There is no way to disable `-Werror` for specific lines of code.

I would use something like this:


// I want errors about conversion here

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Werror=conversion"
// I don't want errors about conversion here
#pragma GCC diagnostic push

// I want errors about conversion here
Comment 1 Andrew Pinski 2020-05-09 20:02:37 UTC
#pragma GCC diagnostic ignored "-Wconversion"

is what you want.
If you want it the warning still but not erroring out you use:
#pragma GCC diagnostic warning "-Wconversion"


This mentioned in the documentation too.

https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas
Comment 2 Alejandro Colomar 2020-05-09 21:30:46 UTC
If I use

#pragma GCC diagnostic ignored "-Wconversion"

I will loose the warning.  I still want the warning, but not the error.
That's what I have right now as a workaround, but it's not what I want.

______

And this:

#pragma GCC diagnostic warning "-Wconversion"

hardcodes the warning.  I want to be able to enable or disable "-Wconversion" in the command line.

______

There is no way to express that I want to enable or disable a warning/error at command line, but that some part of the code should never be an error.
Comment 3 Andrew Pinski 2020-05-10 01:17:09 UTC
Reopening because the original bug report was not clear.