| 540 | ----------------------------------------------------------------------------------------------- |
| 541 | == Warnings from Compilers (and other tools) - Code-Round, Suppress Warnings, or Document. == #warnings |
| 542 | |
| 543 | Boost aims to avoid warnings messages as far as is reasonably practicable, |
| 544 | even when compiled with the highest and most pedantic warning level, |
| 545 | avoiding vendor specific extensions if possible. |
| 546 | |
| 547 | '''Some reasons are:''' |
| 548 | |
| 549 | 1 To allow users whose environment enforces these conditions to use Boost code. |
| 550 | |
| 551 | 2 To avoid the nuisance, perhaps overwhelming, of spurious warning messages. |
| 552 | |
| 553 | 3 To improve code quality by focussing library writers attention on potential problems. |
| 554 | |
| 555 | 4 To improve portability by drawing attention to potentially non-portable code. |
| 556 | |
| 557 | 5 To improve compliance with the C++ Standard. |
| 558 | |
| 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 | |
| 562 | 7 To document that warnings have been considered by the library author or maintainer |
| 563 | and are considered not significant. |
| 564 | |
| 565 | Of these, the last is possibly most important. |
| 566 | |
| 567 | '''What to do''' |
| 568 | |
| 569 | 1 Test compilation with the most pedantic setting for the compiler. |
| 570 | |
| 571 | For Microsoft Visual Studio, this means setting level to 4 (command line /W4), |
| 572 | and disabling Microsoft language extensions |
| 573 | Disable MS extensions = Yes, command line option /Za |
| 574 | |
| 575 | For GCC this means -Wall -pendantic |
| 576 | |
| 577 | Using bjam add warnings=all |
| 578 | |
| 579 | 2 Consider each warning and |
| 580 | |
| 581 | a Rewrite the C++ code to avoid the error. For example, a static_cast makes it clear that |
| 582 | the warned-about potential loss of accuracy has been considered but is not believed to be possible or significant. |
| 583 | |
| 584 | Or placing /* comment */ around an unused variable name, allows the name still to be useful documentation. |
| 585 | |
| 586 | b Use the compiler specific mechanism to supress the warning message, but try hard to ensure that this is as local |
| 587 | to the package as possible so that users can still get warnings from *their code*. |
| 588 | |
| 589 | For 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 | |
| 606 | If 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 | |
| 622 | c Repeat this process with other compilers and use their specific supression methods. |
| 623 | |
| 624 | d Document the code and the associated documentation, and build tools like bjam to say that it is not possible |
| 625 | to use some pedantic-ness level for this module, and why. |
| 626 | |
| 627 | |
| 628 | |
| 629 | |
| 630 | |
| 631 | |
| 632 | |