Changes between Version 21 and Version 22 of Guidelines/WarningsGuidelines


Ignore:
Timestamp:
May 16, 2011, 3:43:57 PM (11 years ago)
Author:
Paul A. Bristow
Comment:

More on /Za option now strongly not recommended.

Legend:

Unmodified
Added
Removed
Modified
  • Guidelines/WarningsGuidelines

    v21 v22  
    6161'''For Microsoft Visual Studio''', this means setting level to 4 (command line /W4).[[BR]]
    6262
    63 You might also try compiling with the /Za option to disable MS extensions, but this may not be as useful as one might hope for reasons explained by Stephan T. Lavavej from the Microsoft STL team in an authoritative post at [http://article.gmane.org/gmane.comp.lib.boost.devel/212186/] /Za and Warning Guidelines for VC.
    64 
    65 Briefly, 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 bug which means that valid code fails to compile, and this is not expected to be fixed for some time. Thirdly, is the possible need to link to other libraries, for example regex, that also '''must''' be built with the /Za option. But 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 trouble! 
     63You might imagine that it would be a good idea to compile with the /Za option to disable MS extensions, but this will not be as useful as one might hope for reasons explained by Stephan T. Lavavej from the Microsoft STL team in an authoritative post at [http://article.gmane.org/gmane.comp.lib.boost.devel/212186/] /Za and Warning Guidelines for VC.
     64And more seriously, when using Boost libraries, standard-conforming name lookup is broken.See [https://connect.microsoft.com/VisualStudio/feedback/details/486253/name-lookup-broken-with-za] and note that is has a '''won't fix''' status.
     65
     66Briefly, '''don't use /Za for ANYTHING. It's broken.'''
     67
     68There 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! 
    6669
    6770The ultimate test of C++ code portability is still testing on as wide a variety of platforms as possible.
    6871
    69 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.
     72You might also consider using Microsoft /Wall if available.  You may find
     73[http://www.geoffchappell.com/viewer.htm?doc=studies/msvc/cl/c1xx/warnings/index.htm&tx=2,27&ts=0,3820]
     74a helpful guide to the byzantine complexity of warnings.[[BR]]
     75
     76Having 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.
    7077
    7178To do this, (for code that doesn't deliberately use Microsoft language extensions), use the VS IDE to disable them with Disable MS extensions = Yes, which adds command line option /Za[[BR]]
     
    8390        : # input files
    8491        : # requirements
    85           -<toolset>msvc:<cxxflags>/Za # Requires type_of which requires MS extensions, so cancel /Za.
     92          -<toolset>msvc:<cxxflags>/Za # Requires type_of which requires MS extensions, so cancel /Za to enable extensions.
    8693        : test_pow
    8794;
    8895
    89 Note the leading - switches off the compiler switch /Za, producing output thus:
     96Note the leading - switches '''off''' the compiler switch /Za, producing output thus:
    9097
    9198compile-c-c++ ..\..\..\bin.v2\libs\math\test\test_pow.test\msvc-9.0\debug\asynch-exceptions-on\threading-multi\pow_test.obj
     
    96103
    97104
    98 (You might also consider using Microsoft /Wall if available.  You may find
    99 [http://www.geoffchappell.com/viewer.htm?doc=studies/msvc/cl/c1xx/warnings/index.htm&tx=2,27&ts=0,3820]
    100 a helpful guide to the byzantine complexity of warnings).[[BR]]
    101 
    102 (If you '''really''' wish to make '''all''' of your VS projects in ''' all''' VS solutions compile with other options '''by default''', you might consider (carefully) editing (with a text editor, very carefully, after keeping a copy of the original) the file C:\Program Files\Microsoft Visual Studio 9.0\VC\VCWizards\1033\common.js to change from the Microsoft defaults.  This does not seem to be officially documented as far as I know.  It may save you changing the project properties repeatedly.
     105
     106(If you '''really''' wish to make '''all''' of your VS projects in ''' all''' VS solutions compile with other options '''by default''', you might consider (carefully) editing (with a text editor, very carefully, after keeping a copy of the original) the file C:\Program Files\Microsoft Visual Studio 9.0\VC\VCWizards\1033\common.js
     107
     108(or similarly C:\Program Files\Microsoft Visual Studio 10.0\VC\VCWizards\1033\common.js for VC 10) to change from the Microsoft defaults.  This does not seem to be officially documented as far as I know.  It may save you changing the project properties repeatedly (and is especially useful if you find that because of previous choices, the project wizard's default is to disable extensions).
    103109
    104110{{{
    105111function AddCommonConfig(oProj, strProjectName,bAddUnicode,bForEmptyProject) in the sections for debug and/or release
    106112
    107 CLTool.DisableLanguageExtensions = true; // add to make the default NO MS extensions (but you probably don't want this for Boost code).
     113CLTool.DisableLanguageExtensions = true; // add to make the default NO MS extensions (but you really don't want this for Boost code).
     114
     115CLTool.DisableLanguageExtensions = false; // default, enable language extensions (strongly recommended for all Boost code).
    108116
    109117LinkTool.LinkIncremental = linkIncrementalNo; // add