-   Programming (
-   -   Suppress a particular gcc compiler warning? (

lamar_air 10-22-2007 04:12 PM

Suppress a particular gcc compiler warning?
I know with gcc you can suppress certain types of warnings by using -Wno-error-errorType to suppress errors of type "errorType". But how do you suppress one specific warning. Is there a way to do this with gcc - I understand you can do it with Visual C++ by using pragma then the unique warning id number. But in gcc i don't see unique warning numbers??

Thanks in advance!

PatrickNew 10-22-2007 04:15 PM

I'm not really sure, but why would you need to suppress a warning? It's just a warning, not an error, and later on the bug that the warning is trying to warn you about may sneak into the code elsewhere. If you've blocked that warning, you won't know it until difficult to track logic errors appear.

lamar_air 10-22-2007 04:30 PM

I understand you're concern. The requirement is to have warning free nightly builds and the warning is coming from a 3rd party package so being able to suppress it is desireable. Can anyone give an example of how to use gcc pragmas?

Thanks! :)

PatrickNew 10-22-2007 04:45 PM

Googling around, it seems that gcc doesn't like the pragma. If there's a way to do this with a pragma, they aren't telling. :-) All the sources I can find say to do it with the -Wno-something flags on the compile command. What warning is being given? Can it be covered with a -Wno flag?

lamar_air 10-22-2007 04:53 PM

I agree it seems they had it long ago, then decided it was bad, and now are somewhat making it more available with gcc 3.4.0. No, the -Wno-error doesn't cover it because then it'll supress all warnings of that type not just the ones for that particular class (i think..).

PatrickNew 10-22-2007 05:02 PM

Hrm, that may be the compromise you have to live with. Alternatively, you could just wrap gcc in a little awk script that just strips that warning out. After all, a warning is really nothing more than a line on the screen.

lamar_air 10-23-2007 09:17 AM

That is true, thanks Patrick

phorgan1 10-09-2011 03:04 AM

GCC DOES have pragmas for this, here's how they work.
I wrote this white paper originally as part of a boost wiki, It explains everything there is to know about suppressing warnings with gcc.

All times are GMT -5. The time now is 05:19 AM.