Changes between Version 26 and Version 27 of Guidelines/WarningsGuidelines

Dec 6, 2012, 10:39:58 AM (5 years ago)
Paul A. Bristow

Some more on Clang, but still more needed


  • Guidelines/WarningsGuidelines

    v26 v27  
    774774So starting from 4.2 but before 4.6, just put near the top of the file something like:
    776 #pragma GCC diagnostic ignored "-Wdeprecated-declarations
     776#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
    778778to turn off warnings from that point forward in the file of the use of deprecated declarations.  Problematically, you have no way of knowing what the user had this option set to.  They might have already had the warnings turned on, they might have had them set to ignore, or they might have had them set to cause an error.  At the end of the file, if you do nothing else, the diagnostic for deprecated declarations stays ignored for anything that includes your file.  You can set them to ignored, error, or warning at the end of the file before exiting, but you don't know which to use.  This is sure to cause angst.
    779779====== version 4.6 Now you can restore the user's flags
    780780For version 4.6 or later, you can save the state of the user's diagnostic flags.  You can insert this around the line that causes the spurious warning:
    782782#pragma GCC diagnostic push[[BR]]
    783783#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
    787787#pragma GCC diagnostic pop
    789790Of course this could cover everything from a line up to the whole file, and in between the push and the pop you could make multiple changes to each of multiple options.
    828 These macro names won't collide with GCC macros since their's start with one or two underscores.
     829These macro names won't collide with GCC macros since theirs start with one or two underscores.
    830831(A list of GCC pre-defined macros is at []).
    848849The workaround for this is to add
    850  cxxflags=-Wno-attributes
    852853to the <compileflags> and <linkflags> in user-config file
     865The options -Wpedantic  -Wall and -Wextra will enable nearly all warnings, a good start and a guide to eliminate warnings by recoding as far as possible.
     867-Wall turns on the following warning flags:
     869          -Waddress   
     870          -Warray-bounds (only with -O2) 
     871          -Wc++11-compat 
     872          -Wchar-subscripts 
     873          -Wenum-compare (in C/ObjC; this is on by default in C++)
     874          -Wimplicit-int (C and Objective-C only)
     875          -Wimplicit-function-declaration (C and Objective-C only)
     876          -Wcomment 
     877          -Wformat   
     878          -Wmain (only for C/ObjC and unless -ffreestanding) 
     879          -Wmaybe-uninitialized
     880          -Wmissing-braces (only for C/ObjC)
     881          -Wnonnull 
     882          -Wparentheses 
     883          -Wpointer-sign 
     884          -Wreorder   
     885          -Wreturn-type 
     886          -Wsequence-point 
     887          -Wsign-compare (only in C++) 
     888          -Wstrict-aliasing 
     889          -Wstrict-overflow=1 
     890          -Wswitch 
     891          -Wtrigraphs 
     892          -Wuninitialized 
     893          -Wunknown-pragmas 
     894          -Wunused-function 
     895          -Wunused-label     
     896          -Wunused-value     
     897          -Wunused-variable 
     898          -Wvolatile-register-var
     901    This enables some extra warning flags that are not enabled by -Wall. (This option used to be called -W. The older name is still supported, but the newer name is more descriptive.)
     903              -Wclobbered 
     904              -Wempty-body 
     905              -Wignored-qualifiers
     906              -Wmissing-field-initializers 
     907              -Wmissing-parameter-type (C only) 
     908              -Wold-style-declaration (C only) 
     909              -Woverride-init 
     910              -Wsign-compare 
     911              -Wtype-limits 
     912              -Wuninitialized 
     913              -Wunused-parameter (only with -Wunused or -Wall)
     914              -Wunused-but-set-parameter (only with -Wunused or -Wall) 
     916The option -Wextra also prints warning messages for the following cases:
     918        A pointer is compared against integer zero with `<', `<=', `>', or `>='.
     919        (C++ only) An enumerator and a non-enumerator both appear in a conditional expression.
     920        (C++ only) Ambiguous virtual bases.
     921        (C++ only) Subscripting an array that has been declared `register'.
     922        (C++ only) Taking the address of a variable that has been declared `register'.
     923        (C++ only) A base class is not initialized in a derived class's copy constructor.
     925However, it may still be necessary to suppress those that are not providing any useful guidance and cannot be reasonably eliminated.
     927Many of the method discussed above for GCC should be useful.
     929(Clang is more recent and so probably uses GCC >= 4.6, so the complexity of early GCC versions is absent).
     931To ignore via a command line, to an option like "-Wunused-variable" add a preceeding "no-" thus: "-Wno-unused-variable".
     933In a jamfile, add
    864939Clang also supports suppressing warnings by pragmas, see []
    865940for example
    875950#pragma clang diagnostic ignored "-Wmultichar"
    877 char b = 'df'; // No warning.
     952char b = 'df'; // Avoid a warning that more than one chars are provided.
    879954#pragma clang diagnostic pop
    882958More info needed on Clang.