Boost logo

Boost :

Subject: [boost] Towards a Warning free code policy proposal
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-08-27 12:26:22


Hi all,

Last year there where two long threads about Boost Warning policy. If I'm not wrong nothing was concluded. I think that we can have two warning policies: one respect to the Boost users and one internal for Boost developement.

We can consider that Boost headers can be used by the users as system headers, so no warning is reported for these files. The main advantage I see is that it allows the users to don't mix the warnings comming from Boost and their own warnings.

Next follows a way to disable completly warnings for 3 compilers: Any Boost header file could be surrounded by

#if defined __GNUC__
#pragma GCC system_header
#elif defined __SUNPRO_CC
#pragma disable_warn
#elif defined _MSC_VER
#pragma warning(push, 1)
#endif

and

#if defined __SUNPRO_CC
#pragma enable_warn
#elif defined _MSC_VER
#pragma warning(pop)
#endif

As we want the developer to be able to catch and eliminate as many warning as possible we need some conditional compilation that allows us to enable the warning reporting internally. These could also be useful for users that prefer to see the Boost warnings.

Boost.Exception uses already this policy, sourronding some of its files with

#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
#pragma GCC system_header
#endif
#if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
#pragma warning(push,1)
#endif

and

#if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
#pragma warning(pop)
#endif

I propose to extend this to a 2-level enabling warning system

BOOST_ENABLE_WARNINGS: If defined, enable warnings for all the Boost libraries
BOOST_<LIB>_ENABLE_WARNINGS: If defined, enable warnings for a specific library <LIB>

Regression testers should run with BOOST_WARNING_ENABLED defined. Developers of a library should run with BOOST_<LIB>_WARNING_ENABLED defined at least. Users could enable warnings at any level just by defining the appropriated macro.

With this 2-level enabling policy, the preceding surrounding code becomes:

#if !defined(BOOST_ENABLE_WARNINGS) && !defined(BOOST_LIB_ENABLE_WARNINGS)
#if defined __GNUC__
#pragma GCC system_header
#elif defined __SUNPRO_CC
#pragma disable_warn
#elif defined _MSC_VER
#pragma warning(push, 1)
#endif
#endif

and

#if !defined(BOOST_ENABLE_WARNINGS) && !defined(BOOST_LIB_ENABLE_WARNINGS)
#if defined __SUNPRO_CC
#pragma enable_warn
#elif defined _MSC_VER
#pragma warning(pop)
#endif
#endif

Due to the nature of the GCC solution, this does not work directly within the source (.cpp) file, only within a header (.hpp) file. So if we want to remove the warnings also from the .cpp files we need to move the code to a .hpp file.

// a.cpp

#include "warning_free_wrapper/a.hpp"

Of course this policy don't mean that the developer should not take care of the warnings.

Please, let me know if this policy could satisfy the needs of the Boost users and the developers.

Best,

_____________________
Vicente Juan Botet Escribá
http://viboes.blogspot.com/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk