Changes between Version 23 and Version 24 of Guidelines/WarningsGuidelines


Ignore:
Timestamp:
Dec 17, 2011, 2:51:05 AM (11 years ago)
Author:
Mateusz Loskot
Comment:

Make listed issues a list. Typos fixed.

Legend:

Unmodified
Added
Removed
Modified
  • Guidelines/WarningsGuidelines

    v23 v24  
    6666Briefly, '''don't use /Za for ANYTHING. It's broken.'''
    6767
    68 There are several problems.  Firstly, the latest compilers, especially VC10, is "pretty conformant" and so code is likely to be portable anyway. Secondly, there is a compiler bug(s) which means that valid standard-conforming code fails to compile, and this is marked 'won't fix'. Thirdly, is the probable need to link to other libraries, for example regex, serialization that also '''must''' be built with the /Za option, but some will fail to compile. Finally, since there is no way to distinguish libraries built with and without this option by filename, so that they cannot co-exist: this is a recipe for confusion and trouble! 
     68There are several problems:
     69* Firstly, the latest compilers, especially VC10, is "pretty conformant" and so code is likely to be portable anyway.
     70* Secondly, there is a compiler bug(s) which means that valid standard-conforming code fails to compile, and this is marked 'won't fix'.
     71* Thirdly, is the probable need to link to other libraries, for example regex, serialization that also '''must''' be built with the /Za option, but some will fail to compile.
     72* Finally, since there is no way to distinguish libraries built with and without this option by filename, so that they cannot co-exist: this is a recipe for confusion and trouble! 
    6973
    7074The ultimate test of C++ code portability is still testing on as wide a variety of platforms as possible.
     
    7276You might also consider using Microsoft /Wall if available.  You may find
    7377[http://www.geoffchappell.com/viewer.htm?doc=studies/msvc/cl/c1xx/warnings/index.htm&tx=2,27&ts=0,3820]
    74 a helpful guide to the byzantine complexity of warnings.[[BR]]
     78a helpful guide to the Byzantine complexity of warnings.[[BR]]
    7579
    7680Having said that, if you only have access to a Microsoft platform, before launching code on the full array of testers, you might consider checking if any indications of non-portability emerge from testing with language extensions disabled.  But you will probably just find spurious compilation failures.
     
    8084To a jamfile add  <toolset>msvc:<cxxflags>/Za # disable MS extensions.[[BR]]
    8185
    82 If it proves impossible to compile with the /Za option (it causes trouble with some MS compilers, sometimes), just document this, including a comment in the build jamfile.
    83 
    84 If only one (or a few) modules in a test (or other) build require MS extensions, you can selectively 'switch off' this 'disable' in the 'requirements' in the jamfile, for example:
     86If it proves impossible to compile with the /Za option (it causes trouble with some MS compilers, sometimes), just document this, including a comment in the build Jamfile.
     87
     88If only one (or a few) modules in a test (or other) build require MS extensions, you can selectively 'switch off' this 'disable' in the 'requirements' in the Jamfile, for example:
    8589
    8690{{{
     
    133137Putting options in jam files allows setting to be made for one or more specified compiler(s).
    134138
    135 Some sample options in jamfile.v2 are:
     139Some sample options in Jamfile.v2 are:
    136140
    137141{{{
     
    253257=== Specific Warnings and Suggested Actions. ===
    254258
    255 ''These are just few for starters, and need more, especially for gcc. Suggestions may be wrong! ''
     259''These are just few for starters, and need more, especially for GCC. Suggestions may be wrong! ''
    256260
    257261The pragma or other code required to suppress warnings is in the right hand box, ready for copy and paste.
     
    551555    '''-Wstrict-aliasing=N''' where N is in {1,2,3} - Higher N implies less false positives, at the expense of more work.  Currently there are 3 levels.[[BR]]
    552556        Level 1: Most agressive, quick, very few false negatives, but many false positives.  Might use if higher levels don't warn, but turning on -fstrict-aliasing breaks the code.  Warns about pointer conversions even if pointer not dereferenced.[[BR]]
    553         Level 2: Agressive, quick, not too precise.  Less false positives than Level 1, but more false negatives.  Only warns if pointer is dereferenced.[[BR]]
     557        Level 2: Aggressive, quick, not too precise.  Less false positives than Level 1, but more false negatives.  Only warns if pointer is dereferenced.[[BR]]
    554558        Level 3: Very few false positives and very few false negatives--the default.[[BR]]
    555559    '''-fstrict-aliasing''' - also turned on by -O2, -O3 and -Os.  Tells the compiler that it's ok to do a certain class of optimization based on the type of expressions.  In particular you're promising by using this flag that an object of one type won't reside at the same address as an object of an incompatible type.[[BR]]
    556560    '''-fno-strict-aliasing''' - turns off this optimization.  If this changes the behavior of your code, you have a problem in your code.
    557561
    558     This is trying to let you know that you are asking the compiler to do undefined behavior and it may not do what you think it will do.  As the optimization level increases, the liklihood that you won't like what it does will increase.  I show a simple example later that surprisingly generates the wrong result when optimization at any level is turned on.  Ignore this warning at your own peril.  You are unlikely to care for the undefined behavior that results.
     562    This is trying to let you know that you are asking the compiler to do undefined behavior and it may not do what you think it will do.  As the optimization level increases, the likelihood that you won't like what it does will increase.  I show a simple example later that surprisingly generates the wrong result when optimization at any level is turned on.  Ignore this warning at your own peril.  You are unlikely to care for the undefined behavior that results.
    559563{{{
    560564From the C++ Standard, section 3.10 Lvalues and rvalues