Changes between Version 7 and Version 8 of Guidelines/WarningsGuidelines


Ignore:
Timestamp:
Jan 7, 2011, 3:42:32 PM (12 years ago)
Author:
Paul A. Bristow
Comment:

More on /Za option not now recommended.

Legend:

Unmodified
Added
Removed
Modified
  • Guidelines/WarningsGuidelines

    v7 v8  
    6060
    6161'''For Microsoft Visual Studio''', this means setting level to 4 (command line /W4).[[BR]]
    62 For code that doesn't deliberately use Microsoft language extensions, disable them with Disable MS extensions = Yes, command line option /Za[[BR]]
     62
     63You 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
     65Briefly, 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! 
     66
     67The ultimate test of C++ code portability is still testing on as wide a variety of platforms as possible.
     68
     69Having 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.
     70
     71To 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]]
    6372
    6473To a jamfile add  <toolset>msvc:<cxxflags>/Za # disable MS extensions.[[BR]]
    6574
    66 If it proves impossible to compile with the /Za option (it is reported to cause trouble with the MS compiler, sometimes), just document this, including in the build jamfile.
     75If 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.
    6776
    6877If 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:
     
    91100a helpful guide to the byzantine complexity of warnings).[[BR]]
    92101
    93 (If you 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.
     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.
    94103
    95104{{{
    96105function AddCommonConfig(oProj, strProjectName,bAddUnicode,bForEmptyProject) in the sections for debug and/or release
    97106
    98 CLTool.DisableLanguageExtensions = true; // add to make the default NO MS extensions.
     107CLTool.DisableLanguageExtensions = true; // add to make the default NO MS extensions (but you probably don't want this for Boost code).
    99108
    100109LinkTool.LinkIncremental = linkIncrementalNo; // add
     
    129138      <toolset>msvc:<define>NDEBUG # Define NO debug, or release.
    130139      <toolset>msvc:<asynch-exceptions>on # Needed for Boost.Test
    131       <toolset>msvc:<cxxflags>/Za # Disable MS extensions.
     140      # <toolset>msvc:<cxxflags>/Za # Disable MS extensions, if required, but see above.
    132141      #-<toolset>msvc:<cxxflags>/Za # (Re-)Enable MS extensions if these are definitely required for specific module.
    133142      #  The define of macros below prevent warnings about the checked versions of SCL and CRT libraries.