Suppressing particular warnings for particular lines of code

Yang Zhang yanghatespam@gmail.com
Thu Dec 4 19:47:00 GMT 2008


John (Eljay) Love-Jensen wrote:
> Hi Yang,
> 
>>> In Java, you can insert @SuppressWarnings(...) annotations before a line
>>> to tell javac to suppress certain warnings for that line.  Is there
>>> anything similar for gcc?
> 
>> Anyone?
> 
> For gcc, there are the compile line switches, such as -Wall, -Wextra, and
> other -Wsomething which enable (or using -Wno-something, disable) the
> warning.

Yeah, I know about these - they only apply to the entire source file, 
whereas I'm interested in disabling warnings for particular lines.

> 
> There are no #pragma directives to disable warnings in-line with the code.

I sense an itch here - write a grep-like tool that can filter out 
warnings from gcc based on the presence of certain tokens in your source 
file.  For instance, inserting

   // SuppressWarning(conversion)

into your source should cause the tool to filter out -Wconversion 
warnings for the following line.

Have to think/experiment more about how to deal with multi-line 
statements, though - not sure how gcc numbers lines in its warnings. 
Also, this still won't work with -Werror (which is something I use), as 
gcc itself will refuse to continue with the compilation.
--
Yang Zhang
http://www.mit.edu/~y_z/



More information about the Gcc-help mailing list