Changes between Version 13 and Version 14 of Guidelines/MaintenanceGuidelines


Ignore:
Timestamp:
Nov 5, 2009, 3:13:34 PM (13 years ago)
Author:
Paul A. Bristow
Comment:

1st draft of Boost compiler warnings

Legend:

Unmodified
Added
Removed
Modified
  • Guidelines/MaintenanceGuidelines

    v13 v14  
    538538Discuss the issue on the ML and do a ticket on the Trac system if there is something to improve.
    539539
     540-----------------------------------------------------------------------------------------------
     541== Warnings from Compilers (and other tools) - Code-Round, Suppress Warnings, or Document. == #warnings
     542
     543Boost aims to avoid warnings messages as far as is reasonably practicable,
     544even when compiled with the highest and most pedantic warning level,
     545avoiding vendor specific extensions if possible.
     546
     547'''Some reasons are:'''
     548
     5491  To allow users whose environment enforces these conditions to use Boost code.
     550
     5512  To avoid the nuisance, perhaps overwhelming, of spurious warning messages.
     552
     5533  To improve code quality by focussing library writers attention on potential problems.
     554
     5554  To improve portability by drawing attention to potentially non-portable code.
     556
     5575  To improve compliance with the C++ Standard.
     558
     5596  To make it possible for users to enable high warning levels compiling their own code
     560without being confused by a barrage of warnings from library code.
     561
     5627  To document that warnings have been considered by the library author or maintainer
     563and are considered not significant.
     564
     565Of these, the last is possibly most important.
     566
     567'''What to do'''
     568
     5691  Test compilation with the most pedantic setting for the compiler.
     570
     571For Microsoft Visual Studio, this means setting level to 4 (command line /W4),
     572and disabling Microsoft language extensions
     573Disable MS extensions = Yes, command line option /Za
     574
     575For GCC this means -Wall -pendantic 
     576
     577Using bjam add warnings=all
     578
     5792  Consider each warning and
     580
     581a  Rewrite the C++ code to avoid the error.  For example, a static_cast makes it clear that
     582the warned-about potential loss of accuracy has been considered but is not believed to be possible or significant.
     583
     584Or placing /* comment */ around an unused variable name, allows the name still to be useful documentation.
     585
     586b  Use the compiler specific mechanism to supress the warning message, but try hard to ensure that this is as local
     587to the package as possible so that users can still get warnings from *their code*.
     588
     589For MSVC, this involved pushing to save the current warning state, disabling the warning, and later popping to restore.
     590
     591{{{
     592#if defined(_MSC_VER)
     593#pragma warning(push) // Save warning settings.
     594#pragma warning(disable : 4996) // disable depricated localtime/gmtime warning
     595#endif
     596
     597...
     598
     599#if defined(_MSC_VER)
     600#pragma warning(pop) // Restore warnings to previous state.
     601#endif
     602
     603}}}
     604
     605
     606If the warning is only for a specific compiler version
     607
     608
     609{{{
     610#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
     611#pragma warning(push)
     612#pragma warning(disable:4512) //assignment operator could not be generated
     613#endif
     614
     615...
     616
     617#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
     618#pragma warning(pop)
     619#endif
     620}}}
     621
     622c  Repeat this process with other compilers and use their specific supression methods.
     623
     624d  Document the code and the associated documentation, and build tools like bjam to say that it is not possible
     625to use some pedantic-ness level for this module, and why.
     626
     627
     628
     629
     630
     631
     632