Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC, C: Finding out name of default warnings for use in #pragma ignore

Tags:

c

gcc

warnings

I've learned that I can put

#pragma GCC diagnostic ignored "<warning>"

to the top of a source file in order to suppress warnings related to this particular source file. However, it seems that some names are not specific enough. For example,

#pragma GCC diagnostic ignored "-Wwrite-strings"

does not prevent gcc (4.7.2) from displaying warning messages whose exact names are not given, instead, these messages are followed only by [enabled by default]. I guess I need to know the correct warning names so I can use them in the #pragma line. I've tried

-fdiagnostics-show-option,

but the warnings are then still displayed as [enabled by default].

Is there any way to identiy these warnings or to alternatively suppress warnings related to a specific source file?

Thank you very much!

like image 525
Guybrush Avatar asked Apr 14 '13 09:04

Guybrush


1 Answers

You have to push and pop diagnostic states. Like this:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
    /* ignoring warning */

    int unused_function( void ) {
         return 1337;
    }
#pragma GCC diagnostic pop
like image 194
Man Vs Code Avatar answered Sep 20 '22 15:09

Man Vs Code