Changes between Version 15 and Version 16 of Guidelines/MaintenanceGuidelines
- Timestamp:
- Nov 5, 2009, 4:59:45 PM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Guidelines/MaintenanceGuidelines
v15 v16 539 539 540 540 ----------------------------------------------------------------------------------------------- 541 == Warnings from Compilers (and other tools) - Code-Round, Suppress Warnings, or Document. == #warnings 541 == Managing Warnings from Compilers (and other tools) == #warnings 542 543 === Avoid warnings, Eliminate warning, Suppress Warnings, or Document. === 542 544 543 545 Boost aims to avoid warnings messages as far as is reasonably practicable, … … 545 547 avoiding vendor specific extensions if possible. 546 548 547 ''' Some reasons are:'''548 549 1 To allow users whose environment enforces these conditionsto use Boost code.549 '''Reasons to eliminate or suppress warnings:''' 550 551 1 To allow users, whose environment requires no warnings, to use Boost code. 550 552 551 553 2 To avoid the nuisance, perhaps overwhelming, of spurious warning messages. 552 554 553 3 To improve code quality by focus sing library writersattention on potential problems.554 555 4 To improve portability by drawing attention topotentially non-portable code.555 3 To improve code quality by focusing library writers' attention on potential problems. 556 557 4 To improve portability by focusing developer attention on potentially non-portable code. 556 558 557 559 5 To improve compliance with the C++ Standard. 558 560 559 6 To make it possible for users to enable high warning levels compiling their own code 560 without being confused by a barrage of warnings from library code. 561 6 To permit users to set high warning levels when using Boost libraries without being overwhelmed with a barrage of library warnings. 561 562 562 563 7 To document that warnings have been considered by the library author or maintainer … … 575 576 For GCC this means -Wall -pendantic 576 577 577 Using bjam add warnings=all to the invocation line. 578 but you might consider adding specific warnings that are to be suppressed, for example: 579 580 -pedantic -Wall -Wno-long-long -Wno-unused-value 581 582 but this is a global setting, so you need to document that these warning must be suppressed by users of this module. This may be acceptable if they are building a library of entirely Boost modules. 583 584 Using bjam add warnings=all to the invocation command line. 578 585 579 586 Putting options in jam files allows setting to be made for one or more specified compiler(s). … … 604 611 }}} 605 612 613 Using warning-as-errors will make it hard to miss warnings. 614 Microsoft command line option /WX, 615 gcc option -warning-as-errors 616 606 617 2 Consider each warning and 607 618 608 a Rewrite the C++ code to avoid the error. For example, a static_cast makes it clear that 609 the warned-about potential loss of accuracy has been considered but is not believed to be possible or significant. 610 611 Or placing /* comment */ around an unused variable name, allows the name still to be useful documentation. 612 613 b Use the compiler specific mechanism to supress the warning message, but try hard to ensure that this is as local 619 a Rewrite the code to avoid the warning, if possible. For example, adding a static_cast will indicate that any warning about loss of accuracy has been judged not possible or significant. Remove or comment out parameters to avoid warnings about unused parameters. Placing /* comment */ around an unused variable name, allows the name still to be useful documentation. 620 621 b Use the compiler specific mechanism to suppress the warning message, but try hard to ensure that this is as local 614 622 to the package as possible so that users can still get warnings from *their code*. 615 623 … … 620 628 #if defined(_MSC_VER) 621 629 #pragma warning(push) // Save warning settings. 622 #pragma warning(disable : 4996) // disable deprecated localtime/gmtime warning.630 #pragma warning(disable : 4996) // Disable deprecated localtime/gmtime warning. 623 631 #endif 624 632 … … 631 639 }}} 632 640 633 634 If the warning is only for a specific compiler version 635 641 If the warning is only for a specific compiler version, us this approach: 636 642 637 643 {{{ … … 648 654 }}} 649 655 650 c Repeat this process with other compilers and use their specific supression methods. 651 652 d Document the code and the associated documentation, and build tools like bjam to say that it is not possible 653 to use some pedantic-ness level for this module, and why. 654 655 656 657 658 659 660 656 c Repeat this process with other compilers and use their specific suppression methods. 657 658 d If a warning cannot be eliminated or suppressed, explain why in the code and the documentation. If appropriate, document in build files, as well. Consider indicating the highest warning level possible or compiler-specific settings that will provide a warning-free build. 659 660 661 662 663