Changes between Version 19 and Version 20 of Guidelines/WarningsGuidelines


Ignore:
Timestamp:
Mar 26, 2011, 10:49:05 PM (12 years ago)
Author:
phorgan1
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Guidelines/WarningsGuidelines

    v19 v20  
    726726  Available since GCC version 4.6, this pragma lets you remember diagnostic options in place at a particular time.  This pragma can occur on any line of a file.  The number of nested pushes is limited only by the size of memory and the size of an int index into the diagnostic information.
    727727 #pragma GCC diagnostic pop::
    728   Available since GCC version 4.6, this pragma lets you restore diagnostic options that were remembered by a diagnostic push. This pragma can occur on any line of a file.  The number of pops is limited by memory and the size of an int index into the diagnostic information.  At a pop information is moved from the table used by push into a history.  An unbalanced pop, i.e. popping when nothing is on the stack is harmless and will simply reassert the user's command line diagnostic choices.
     728  Available since GCC version 4.6, this pragma lets you restore diagnostic options that were remembered by a diagnostic push. This pragma can occur on any line of a file.  The number of pops is limited by memory and the size of an int index into the diagnostic information.  At a pop information is moved from the table used by push into a history.  An unbalanced pop, i.e. popping when nothing is on the stack is harmless and will simply reassert the user's command line diagnostic choices.    Be careful, though, that you don't pop to soon.  In this example:
     729{{{
     730foo()
     731{
     732    int unused,i;
     733    i=3;
     734}
     735}}}
     736We might want to suppress the unused variable like this:
     737{{{
     738foo()
     739{
     740#pragma GCC diagnostic push
     741#pragma GCC diagnostic "-Wunused-variable"
     742    int unused,i;
     743#pragma GCC diagnostic pop
     744    i=3;
     745}
     746}}}
     747and then be surprised that we still get a warning about an unused variable.  The reason is, that GCC doesn't know the variable is unused until it hits the closing brace.  That means the pop has to come after the closing brace:
     748{{{
     749foo()
     750{
     751#pragma GCC diagnostic push
     752#pragma GCC diagnostic "-Wunused-variable"
     753    int unused,i;
     754    i=3;
     755}
     756#pragma GCC diagnostic pop
     757}}}
     758
    729759 #pragma GCC diagnostic [warning|error|ignored] OPTION::
    730760  From GCC version 4.2.4 and before GCC version 4.6 this could be specified at file scope outside of any functions, classes, unions, structs, or methods, to change the behavior when a particular class of error was seen.  For GCC version 4.6 and later, it can be put in any line of a file, and affects from that position forward.  For any supported version, it only works with warnings that have explicit -W arguments, use -fdiagnostic-show-option to find out which one to use.  An example: #pragma GCC diagnostic ignored "-Wdeprecated-declarations"