Changes between Version 23 and Version 24 of Guidelines/WarningsGuidelines
- Timestamp:
- Dec 17, 2011, 2:51:05 AM (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Guidelines/WarningsGuidelines
v23 v24 66 66 Briefly, '''don't use /Za for ANYTHING. It's broken.''' 67 67 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! 68 There 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! 69 73 70 74 The ultimate test of C++ code portability is still testing on as wide a variety of platforms as possible. … … 72 76 You might also consider using Microsoft /Wall if available. You may find 73 77 [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]]78 a helpful guide to the Byzantine complexity of warnings.[[BR]] 75 79 76 80 Having 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. … … 80 84 To a jamfile add <toolset>msvc:<cxxflags>/Za # disable MS extensions.[[BR]] 81 85 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:86 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. 87 88 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: 85 89 86 90 {{{ … … 133 137 Putting options in jam files allows setting to be made for one or more specified compiler(s). 134 138 135 Some sample options in jamfile.v2 are:139 Some sample options in Jamfile.v2 are: 136 140 137 141 {{{ … … 253 257 === Specific Warnings and Suggested Actions. === 254 258 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! '' 256 260 257 261 The pragma or other code required to suppress warnings is in the right hand box, ready for copy and paste. … … 551 555 '''-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]] 552 556 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: Ag ressive, 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]] 554 558 Level 3: Very few false positives and very few false negatives--the default.[[BR]] 555 559 '''-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]] 556 560 '''-fno-strict-aliasing''' - turns off this optimization. If this changes the behavior of your code, you have a problem in your code. 557 561 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 lik lihood 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. 559 563 {{{ 560 564 From the C++ Standard, section 3.10 Lvalues and rvalues