Towards a Warning free code policy proposal

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/

vicente.botet wrote:
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.
[snip] The problem I foresee is that many warnings won't be triggered or useful until templates are instantiated by users with specific types. _____ Rob Stewart robert.stewart@sig.com Software Engineer, Core Software using std::disclaimer; Susquehanna International Group, LLP http://www.sig.com IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

----- Original Message ----- From: "Stewart, Robert" <Robert.Stewart@sig.com> To: <boost@lists.boost.org> Sent: Friday, August 27, 2010 6:38 PM Subject: Re: [boost] Towards a Warning free code policy proposal
vicente.botet wrote:
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.
[snip]
The problem I foresee is that many warnings won't be triggered or useful until templates are instantiated by users with specific types. _____ Rob Stewart robert.stewart@sig.com
Yes, you are right. The user wanting to improve Boost could build her/his product defining BOOST_ENABLE_WARNINGS, but s/he can avoid all the Boost warnings by default. This should help some companies having a strict warning policy to adopt Boost. Vicente

On Fri, Aug 27, 2010 at 9:38 AM, Stewart, Robert <Robert.Stewart@sig.com> wrote:
vicente.botet wrote:
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.
[snip]
The problem I foresee is that many warnings won't be triggered or useful until templates are instantiated by users with specific types.
I haven't done any tests but I'm assuming that #pragma GCC system_header is smart wrt this issue (for some definition of smart) because this pragma is used in their STL implementation headers, with the same desired effect and the same concerns. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

On Fri, Aug 27, 2010 at 8:26 AM, vicente.botet <vicente.botet@wanadoo.fr> wrote:
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
If we want to do something like that, it should be encapsulated in #include files: #include <boost/detail/header_prefix.hpp> ... #include <boost/detail/header_suffix.hpp> -- Dave Abrahams BoostPro Computing http://www.boostpro.com

On 8/27/2010 11:26 AM, Dave Abrahams wrote:
On Fri, Aug 27, 2010 at 8:26 AM, vicente.botet<vicente.botet@wanadoo.fr> wrote:
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
If we want to do something like that, it should be encapsulated in #include files:
#include<boost/detail/header_prefix.hpp>
...
#include<boost/detail/header_suffix.hpp>
I have never used the "GCC system_header" pragma, and have only gleaned its purpose from this list. Based only on that, it doesn't sound like you can stick it in an encapsulation header as above. But other than that, yes, putting the MSVC and sun pragmas in prefix/suffix files would be good. - Jeff

On Fri, Aug 27, 2010 at 11:26 AM, Dave Abrahams <dave@boostpro.com> wrote:
If we want to do something like that, it should be encapsulated in #include files:
#include <boost/detail/header_prefix.hpp>
...
#include <boost/detail/header_suffix.hpp>
I haven't tried this but I've assumed that #pragma GCC system_header affects only the header that refers to it. If that's correct, then the prefix/suffix approach won't work. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

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.
There was some progress towards fixing warnings: https://svn.boost.org/trac/boost/wiki/WarningFixes Also I'm fairly sure that Paul Bristow started a "How to fix warnings" guidelines page, but I can't find it right now :-(
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
I'm completely against disabling warnings in such a blanket manner for a number of reasons: 1) It doesn't fix anything, it hides it. 2) I have found legitimate bugs in both my code and others as a result of fixing what looked to be "busy-body" warnings at first glance. Unfortunately, not all have been fixed: for example https://svn.boost.org/trac/boost/ticket/3606 3) As others have noted, some warnings are only emitted when a template is instantiated with certain template arguments - in this case the warning may be telling the user something important about the template arguments that they're using and *should be seen*. 4) Blanket disabling does nothing for compilers that don't have such mechanisms - indeed I would contend that it would make things worse, as the trend would be towards "don't worry about warnings". 5) I worry that this would lead towards poorer quality code and an "out of sight out of mind" mentality. 6) As a last resort, we can always resort to - preferably selective - disabling methods when all else fails. So... yes we need to do something about warnings, and yes I would like to see our tests run with "warnings as errors" for some compilers at least, but please not like this! Anyhow, I'll jump down off my soap box now ;-) John

John Maddock wrote:
I'm completely against disabling warnings in such a blanket manner for a number of reasons:
1) It doesn't fix anything, it hides it. 2) I have found legitimate bugs in both my code and others as a result of fixing what looked to be "busy-body" warnings at first glance. Unfortunately, not all have been fixed: for example https://svn.boost.org/trac/boost/ticket/3606 3) As others have noted, some warnings are only emitted when a template is instantiated with certain template arguments - in this case the warning may be telling the user something important about the template arguments that they're using and *should be seen*. 4) Blanket disabling does nothing for compilers that don't have such mechanisms - indeed I would contend that it would make things worse, as the trend would be towards "don't worry about warnings". 5) I worry that this would lead towards poorer quality code and an "out of sight out of mind" mentality. 6) As a last resort, we can always resort to - preferably selective - disabling methods when all else fails.
So... yes we need to do something about warnings, and yes I would like to see our tests run with "warnings as errors" for some compilers at least, but please not like this!
Anyhow, I'll jump down off my soap box now ;-)
John
I totally agree with this. When targeting a specific compiler, a 3rd party library can use non-standard but implementation defined behavior. You cannot use implementation specific behavior, especially not if it is undocumented. The implementor of a specific compiler's standard library can, and probably must, use these extensions. However, when they are "granted on an ad-hoc basis" http://gcc.gnu.org/onlinedocs/cpp/System-Headers.html it would be extremely dangerous for anyone else to rely on these features. How do we know exactly what they are, or when they change? Bo Persson

On 28 August 2010 10:26, John Maddock <boost.regex@virgin.net> wrote:
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.
There was some progress towards fixing warnings:
https://svn.boost.org/trac/boost/wiki/WarningFixes
Also I'm fairly sure that Paul Bristow started a "How to fix warnings" guidelines page, but I can't find it right now :-(
Oh, sorry about that. I removed the links when I moved the guidelines back to the main website and forgot to provide a way to find the wiki guidelines. https://svn.boost.org/trac/boost/wiki/Guidelines Daniel

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Daniel James Sent: Saturday, August 28, 2010 11:14 AM To: boost@lists.boost.org Subject: Re: [boost] Towards a Warning free code policy proposal
On 28 August 2010 10:26, John Maddock <boost.regex@virgin.net> wrote:
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.
There was some progress towards fixing warnings:
https://svn.boost.org/trac/boost/wiki/WarningFixes
Also I'm fairly sure that Paul Bristow started a "How to fix warnings" guidelines page, but I can't find it right now :-(
Oh, sorry about that. I removed the links when I moved the guidelines back to the main website and forgot to provide a way to find the wiki guidelines.
More specifically for your bookmarks ;-) https://svn.boost.org/trac/boost/wiki/Guidelines/WarningsGuidelines I think a major problem is that gcc doesn't allow as localised warning suppression as MSVC. gcc users could usefully 'moan louder' about this. It will always be necessary to suppress warnings - if only when the compiler is raising a false alarm, and it won't be fixed for some time. A recent example is at http://connect.microsoft.com/VisualStudio/feedback/details/586147/warning-c4 224-is-given-for-correct-code-if-ms-extensions-are-disabled http://tinyurl.com/2blmq3l This will prevent the hapless user, condemned to use \Za, getting a 4 page slap in the face for having the temerity to ask for a student's t value! But C4224 warnings can be valid and useful, so warning suppression really should be localised. Paul --- Paul A. Bristow, Prizet Farmhouse, Kendal LA8 8AB UK +44 1539 561830 07714330204 pbristow@hetp.u-net.com

----- Original Message ----- From: "John Maddock" <boost.regex@virgin.net> To: <boost@lists.boost.org> Sent: Saturday, August 28, 2010 11:26 AM Subject: Re: [boost] Towards a Warning free code policy proposal
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.
There was some progress towards fixing warnings:
https://svn.boost.org/trac/boost/wiki/WarningFixes
Also I'm fairly sure that Paul Bristow started a "How to fix warnings" guidelines page, but I can't find it right now :-(
I can see it now that the wiki has been recovered.
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
I'm completely against disabling warnings in such a blanket manner for a number of reasons:
1) It doesn't fix anything, it hides it.
I would say, it enables users to hide Boost warnings. If you prefer instead on setting the defaul as warnings disabled, we can enable them as default, and let the user disable them with just one define.
2) I have found legitimate bugs in both my code and others as a result of fixing what looked to be "busy-body" warnings at first glance. As I said in the initial post: "Of course this policy don't mean that the developer should not take care of the warnings. " 3) As others have noted, some warnings are only emitted when a template is instantiated with certain template arguments - in this case the warning may be telling the user something important about the template arguments that they're using and *should be seen*.
The user can always define BOOST_ENABLE_WARNINGS, so warnings will be no suppresed using this technique.
4) Blanket disabling does nothing for compilers that don't have such mechanisms -
Well there are 3 main compiler family that allow it. I don't know for others.
indeed I would contend that it would make things worse, as the trend would be towards "don't worry about warnings".
I don't agree. If regressions are runned with BOOST_ENABLE_WARNINGS and if as other sugested we have some compilers with warning-as-error set, this could be the bases of a clear warning free strategy.
5) I worry that this would lead towards poorer quality code and an "out of sight out of mind" mentality.
I repeat. I'm not purposing to don't fix the warnings. Just to give the user the posibility to supress all the Boost warnings.
6) As a last resort, we can always resort to - preferably selective - disabling methods when all else fails.
I agree, we need to eliminate the warnings and suppress them when all else fails in the most localized way. The problem is that currently there are a lot of warnings that are not hadled. The strategy I'm porposing just helps to achieve 0 warnings (for some compilers :) for users that needs this warning free code as a preamble to install Boost on his project.
So... yes we need to do something about warnings, and yes I would like to see our tests run with "warnings as errors" for some compilers at least, but please not like this!
Could some of the testers set up a configuration with warnings as errors set? Best, Vicente

I'm completely against disabling warnings in such a blanket manner for a number of reasons:
1) It doesn't fix anything, it hides it.
I would say, it enables users to hide Boost warnings. If you prefer instead on setting the defaul as warnings disabled, we can enable them as default, and let the user disable them with just one define.
2) I have found legitimate bugs in both my code and others as a result of fixing what looked to be "busy-body" warnings at first glance. As I said in the initial post: "Of course this policy don't mean that the developer should not take care of the warnings. "
Sure, but the incentive to do so is removed.
3) As others have noted, some warnings are only emitted when a template is instantiated with certain template arguments - in this case the warning may be telling the user something important about the template arguments that they're using and *should be seen*.
The user can always define BOOST_ENABLE_WARNINGS, so warnings will be no suppresed using this technique.
I don't believe a casual user will realise that such a thing is needed or available - boost is complex enough to get to grips with already.
4) Blanket disabling does nothing for compilers that don't have such mechanisms -
Well there are 3 main compiler family that allow it. I don't know for others.
indeed I would contend that it would make things worse, as the trend would be towards "don't worry about warnings".
I don't agree. If regressions are runned with BOOST_ENABLE_WARNINGS and if as other sugested we have some compilers with warning-as-error set, this could be the bases of a clear warning free strategy.
5) I worry that this would lead towards poorer quality code and an "out of sight out of mind" mentality.
I repeat. I'm not purposing to don't fix the warnings. Just to give the user the posibility to supress all the Boost warnings.
I understand that, I'm just saying that human nature being what it is, the chances of any warnings actually getting fixed if they've been explicitly disable is close to zero IMO.
6) As a last resort, we can always resort to - preferably selective - disabling methods when all else fails.
I agree, we need to eliminate the warnings and suppress them when all else fails in the most localized way. The problem is that currently there are a lot of warnings that are not hadled. The strategy I'm porposing just helps to achieve 0 warnings (for some compilers :) for users that needs this warning free code as a preamble to install Boost on his project.
Maybe. The interesting thing is, I don't believe we're that far from zero warnings for most libraries anyway, it just requires someone to care enough to fix them (usually not hard IMO), and for the maintainer to care enough to apply the patches.
So... yes we need to do something about warnings, and yes I would like to see our tests run with "warnings as errors" for some compilers at least, but please not like this!
Could some of the testers set up a configuration with warnings as errors set?
That would certainly focus minds :-) John.

I've casually followed this discussion and I'm sort of left confused. My experience with trying to get to zero warnings is pretty simple. I looked at each warning. a) some were potential bugs and it was easy to fix - I fixed them. b) some were potential bugs and harder to fix - I fixed them. c) some were "cosmetic" bugs - e.g. declaration hide a base class variable - I fixed most of them. But in some cases that was my explicit intention d) some were too hard to fix/eliminate comparison between signed/unsigned - I just left them because I didn't know how to fix them e) some were "cosmetic" warning which varied a lot between compilers. This started to turn into a game of "whack-a-mole" in that that seemed to be never ending and would require a lot of compiler specific code - I left them. f) some were in the library build - I considered these lower priority as they would only occur at install time. g) some were in tests - I considered these slightly higher priority but still left some. My reasoning is that it seems that users never run the test suite for libraries they use. (another topic) h) the rest would show in users code - I considered highest priority since this is were most users would see the warnings. In addition, I use BOOST_SERIALIZATION_STATIC_WARNING in lots of places to flag code which is unlikely to produce what the user intended. for example, exporting a derived class which is not virtual will not result in serializing a derived class through a base class pointer. I'm not proposing anything. I'm just saying that trying to get a "policy" on warnings seems likely to fail in my opinion. Requiring 0 warnings is not realistic. The only thing I can suggest is a) expect a reasonable effort to minimize warnings b) specific places where they can't be eliminated on all platforms should have a comment in the source code at the right spot. c) perhaps a short statement on some warnings which can't be surpressed in the libraries release notes or documentation Robert Ramey

On Sat, 2010-08-28 at 22:17 +0300, Robert Ramey wrote:
d) some were too hard to fix/eliminate comparison between signed/unsigned - I just left them because I didn't know how to fix them
Am I missing some complication I'm not aware of? In my experience this warning is just about always the result of using int for variables which should be of type size_t, as in for(int i=0; i<object.size(); i++) If I cannot redefine all the types to unsigned, something like this usually fixes the problem: if ( size >= 0 && static_cast<size_t>(size) < object.size() ) Writing static_casts is annoying, but it is often necessary if you want to remain -Wall -pedantic. --> Mika Heiskanen

On Sat, Aug 28, 2010 at 2:11 PM, Mika Heiskanen <mika.heiskanen@fmi.fi> wrote:
On Sat, 2010-08-28 at 22:17 +0300, Robert Ramey wrote:
d) some were too hard to fix/eliminate comparison between signed/unsigned - I just left them because I didn't know how to fix them
Am I missing some complication I'm not aware of?
In my experience this warning is just about always the result of using int for variables which should be of type size_t, as in
for(int i=0; i<object.size(); i++)
If I cannot redefine all the types to unsigned, something like this usually fixes the problem:
if ( size >= 0 && static_cast<size_t>(size) < object.size() )
Writing static_casts is annoying, but it is often necessary if you want to remain -Wall -pedantic.
This is a good illustration of one of the problems with "fixing" warnings: this is often done with casts, and casts are way more dangerous than the built-in implicit conversions for which the compiler is warning about. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

On Sun, 2010-08-29 at 09:23 +0300, Emil Dotchevski wrote:
On Sat, Aug 28, 2010 at 2:11 PM, Mika Heiskanen <mika.heiskanen@fmi.fi> wrote:
In my experience this warning is just about always the result of using int for variables which should be of type size_t, as in
for(int i=0; i<object.size(); i++)
If I cannot redefine all the types to unsigned, something like this usually fixes the problem:
if ( size >= 0 && static_cast<size_t>(size) < object.size() )
Writing static_casts is annoying, but it is often necessary if you want to remain -Wall -pedantic.
This is a good illustration of one of the problems with "fixing" warnings: this is often done with casts, and casts are way more dangerous than the built-in implicit conversions for which the compiler is warning about.
I did try to imply changing size types to be unsigned is the better solution, since then there will be nothing to warn about. With 3rd party libraries that is not always possible, and for me boost is a 3rd party library. Having said that, I do not recall ever having to static_cast anything when using boost, the warnings usually appear when using legacy code. --> Mika Heiskanen

On 29 August 2010 01:23, Emil Dotchevski <emil@revergestudios.com> wrote:
Writing static_casts is annoying, but it is often necessary if you want to remain -Wall -pedantic.
This is a good illustration of one of the problems with "fixing" warnings: this is often done with casts, and casts are way more dangerous than the built-in implicit conversions for which the compiler is warning about.
Is it really worse? Here are the situations we are comparing: 1. Silencing the warnings so that users and library developers can't look at them. 2. Generating hundreds to thousands of warnings so that users and library developers don't look at them. The only way to effectively use warnings to look for problems is to have a zero warning policy. -- Nevin Liber <mailto:nevin@eviloverlord.com> (847) 691-1404

On Mon, Aug 30, 2010 at 8:36 AM, Nevin Liber <nevin@eviloverlord.com> wrote:
On 29 August 2010 01:23, Emil Dotchevski <emil@revergestudios.com> wrote:
Writing static_casts is annoying, but it is often necessary if you want to remain -Wall -pedantic.
This is a good illustration of one of the problems with "fixing" warnings: this is often done with casts, and casts are way more dangerous than the built-in implicit conversions for which the compiler is warning about.
Is it really worse? Here are the situations we are comparing:
1. Silencing the warnings so that users and library developers can't look at them. 2. Generating hundreds to thousands of warnings so that users and library developers don't look at them.
The only way to effectively use warnings to look for problems is to have a zero warning policy.
I rarely "fix" warnings that interfere with my design decisions. For example, I won't add a virtual destructor just to please the compiler, I won't use a cast to silence a warning about a perfectly legal implicit type conversion, and I can't even begin to think about calling fopen_s. My point is, in practice not all warnings can or should be fixed, and we need to 3. Use other means to prevent users from seeing such warnings. ...or we can ignore the problem altogether. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

On 28/08/2010 22:11, Mika Heiskanen wrote:
On Sat, 2010-08-28 at 22:17 +0300, Robert Ramey wrote:
d) some were too hard to fix/eliminate comparison between signed/unsigned - I just left them because I didn't know how to fix them
Comparing signed and unsigned integers can be a serious issue, since that means you might not deal with negative cases properly, which is why there are warnings.
Am I missing some complication I'm not aware of?
In my experience this warning is just about always the result of using int for variables which should be of type size_t, as in
for(int i=0; i<object.size(); i++)
I never understood why some people even write code like this. There are several problems with this: - using int, even though int has no direct relation with the size type of 'object' - using indexes and size instead of iterators, which have an idiomatic way to be traversed - making the code rely on a particular data structure, instead of allowing it to work with any sequence type, allowing the code to be more easily changed.
If I cannot redefine all the types to unsigned, something like this usually fixes the problem:
if ( size>= 0&& static_cast<size_t>(size)< object.size() )
size_t(size) instead of static_cast<size_t>(size) should work just fine. No need for any cast.

On Sun, Aug 29, 2010 at 1:50 AM, Mathias Gaunard <mathias.gaunard@ens-lyon.org> wrote:
size_t(size) instead of static_cast<size_t>(size) should work just fine. No need for any cast.
The problem with that is that size_t(size) *is* a dangerous c-style cast unless size_t has a nontrivial constructor. -- Dave Abrahams BoostPro Computing http://www.boostpro.com

On Sun, Aug 29, 2010 at 2:50 AM, Mathias Gaunard <mathias.gaunard@ens-lyon.org> wrote:
I never understood why some people even write code like this. There are several problems with this: - using int, even though int has no direct relation with the size type of 'object' - using indexes and size instead of iterators, which have an idiomatic way to be traversed - making the code rely on a particular data structure, instead of allowing it to work with any sequence type, allowing the code to be more easily changed.
This is besides the point.
If I cannot redefine all the types to unsigned, something like this usually fixes the problem:
if ( size>= 0&& static_cast<size_t>(size)< object.size() )
size_t(size) instead of static_cast<size_t>(size) should work just fine. No need for any cast.
T(x) is even more dangerous than static_cast because in certain situations it is equivalent to a C-style cast. The safest thing to do is to let the carefully designed implicit conversion system of the language take care of things. At most, I'd add assert(size>=0) but that's often an overkill. The best way to avoid this warning in this case is to compare with != instead of <. I like != better anyway because it is less defensive, it breaks easier if I mess up the loop. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

On 29 August 2010 04:50, Mathias Gaunard <mathias.gaunard@ens-lyon.org> wrote:
for(int i=0; i<object.size(); i++)
I never understood why some people even write code like this. There are several problems with this: - using int, even though int has no direct relation with the size type of 'object'
Until C++0x and auto, it can be fairly painful to get size_type of the container, since you can't get it from the "object" variable itself. Personally, I go through the pain, but I can certainly understand why others may not. Library code, such as Boost, should do this for correctness.
- using indexes and size instead of iterators, which have an idiomatic way to be traversed
push_back(), for instance, may invalidate iterators with a vector or deque but will not invalidate indices.
- making the code rely on a particular data structure, instead of allowing it to work with any sequence type, allowing the code to be more easily changed.
Even std::sort doesn't work on *any* sequence type. There are usually other requirements (random access, contiguous space, O(1) insertion/removal, etc.) that limit the choice of data structures. -- Nevin Liber <mailto:nevin@eviloverlord.com> (847) 691-1404

On 30.08.2010 19:26, Nevin Liber wrote:
On 29 August 2010 04:50, Mathias Gaunard<mathias.gaunard@ens-lyon.org> wrote:
for(int i=0; i<object.size(); i++)
I never understood why some people even write code like this. There are several problems with this: - using int, even though int has no direct relation with the size type of 'object'
Until C++0x and auto, it can be fairly painful to get size_type of the container, since you can't get it from the "object" variable itself. Personally, I go through the pain, but I can certainly understand why others may not. Library code, such as Boost, should do this for correctness.
In such cases I simply use std::size_t. In 99.999% of cases it is the size_type of the container and it's short enough.

Hi all, On Sat, Aug 28, 2010 at 01:26, vicente.botet <vicente.botet@wanadoo.fr> wrote:
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. ...
Please, let me know if this policy could satisfy the needs of the Boost users and the developers.
As a user who is somewhat following the discussion, I have to say that the approach used by gcc in terms of handling warnings is good. Warnings are shown and you have to add flags such as -Wall to disable them. That at least forces users to do something because of the warnings -- either act on it by looking at their code or realizing that the warning is unimportant and to find the flag that would remove it. Perhaps a more viable solution is to produce warnings and errors that could be searched in a part of the Boost documentation (i.e., dedicated to dealing with warnings) that says what caused the warning and how to disable it if the user is satisfied that it is not important. I can see why this issue would be brought up -- boost warnings are intimidating to users. But (IMHO), removing warnings will make users not knowledgeable in Boost (such as myself) to becoming more sloppy. Instead of that, maybe keeping the warnings but having documentation specifically explaining how they can be suppressed might be a bit better than having them off by default for users. Another idea is that I tend to use colorgcc to color the output from gcc. Perhaps modifying colorgcc or producing a separate wrapper which colors warnings based on severity might be another idea... Ray

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Raymond Wan Sent: Sunday, August 29, 2010 6:53 AM To: boost@lists.boost.org Subject: Re: [boost] Towards a Warning free code policy proposal <snip>
As a user who is somewhat following the discussion, I have to say that the approach used by gcc in terms of handling warnings is good. Warnings are shown and you have to add flags such as -Wall to disable them. That at least forces users to do something because of the warnings -- either act on it by looking at their code or realizing that the warning is unimportant and to find the flag that would remove it. Perhaps a more viable solution is to produce warnings and errors that could be searched in a part of the Boost documentation (i.e., dedicated to dealing with warnings) that says what caused the warning and how to disable it if the user is satisfied that it is not important.
I can see why this issue would be brought up -- boost warnings are intimidating to users. But (IMHO), removing warnings will make users not knowledgeable in Boost (such as myself) to becoming more sloppy. Instead of that, maybe keeping the warnings but having documentation specifically explaining how they can be suppressed might be a bit better
https://svn.boost.org/trac/boost/wiki/Guidelines/WarningsGuidelines tells you quite a lot about warnings, including gcc and MSVC (It's a bit thin on other compilers - more info please). than
having them off by default for users.
I'd like to see Boost getting rid of warnings that come from its code, so that all warnings are relevant to the user. The above, and references therein, (written for Boost developers) may still be useful to users. Paul --- Paul A. Bristow, Prizet Farmhouse, Kendal LA8 8AB UK +44 1539 561830 07714330204 pbristow@hetp.u-net.com

On Sun, Aug 29, 2010 at 02:52:58PM +0900, Raymond Wan wrote:
As a user who is somewhat following the discussion, I have to say that the approach used by gcc in terms of handling warnings is good. Warnings are shown and you have to add flags such as -Wall to disable them.
I think you got that wrong. From 'man gcc': -Wall All of the above -W options combined. This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros. This also enables some language- specific warnings described in C++ Dialect Options and Objective-C and Objective-C++ Dialect Options. As an aside, I'd love to see boost not produce so many warnings. My own code using boost can usually be compiled free of warnings, if it weren't for those pesky boost headers. It's not that I can't ignore warnings by eye after having figured out what they mean and whether I care about them. It's that with template code you'll include tons of headers tons of times, and a single warning from boost repeated endlessly that way can drown out stuff I want to pay attention to. Anyway... I've dealt with that before, I'll deal with it again, but from a purely wishful thinking point of view, it'd be awesome if boost compiled warning free. Jens -- 1.21 Jiggabytes of memory should be enough for anybody.

Hello All, How to deal with warning? - If code produces warning disable it? You will end with numerous ifdefs for each compiler: GCC, Intel, MSVC, SunStudio and much more. You would even find yourself subdividing each of the following cases for compiler versions where each one of them produce some kind of warning and finally you will disable some important warning accidentally. - If the code is produces warning, fix it. And you end with 100 stupid cases where each compiler thinks it is important, * gcc warns on polymorphic class without virtual destructor even if sometimes you don't need it. * MSVC calls every single standard C library function dangerous like fopen, localtime and so-on. * Intel produces multiple lines of usless remarks on temporary objects. - What warning level to use under GCC -Wall? -Wextra? -Wpedantic? and under MSVC /w2? /w3? or /w4? I have never seen a big project that compiles cleanly with /w4 under MSVC. IMHO: let library developer decide what to disable and what policy he should use. Developer that respects himself would code the way the code compiles with severe warning level. My $0.02 Artyom

On Sun, Aug 29, 2010 at 10:20 PM, Artyom <artyomtnk@yahoo.com> wrote:
IMHO: let library developer decide what to disable and what policy he should use.
My $0.02
Make that $1.02. :) Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

Artyom wrote:
IMHO: let library developer decide what to disable and what policy he should use. Developer that respects himself would code the way the code compiles with severe warning level.
Boost is thought of as a whole made of parts. If the parts differ wildly in how things are addressed, the whole suffers. That's why we have high documentation standards for all Boost libraries, for example. Consequently, without some minimum standard for warnings, there may be too much variation. There should be guidelines on things to avoid when trying to fix warnings. Emil's favorite is to avoid casts because they bypass the implicit type conversion system in the language and can hide problems. I don't agree entirely with his concerns, but there is value in what he says. We need guidelines that prescribe and others that proscribe to ensure best practice. _____ Rob Stewart robert.stewart@sig.com Software Engineer, Core Software using std::disclaimer; Susquehanna International Group, LLP http://www.sig.com IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

On 30.08.2010 15:12, Stewart, Robert wrote:
Artyom wrote:
IMHO: let library developer decide what to disable and what policy he should use. Developer that respects himself would code the way the code compiles with severe warning level.
Boost is thought of as a whole made of parts. If the parts differ wildly in how things are addressed, the whole suffers. That's why we have high documentation standards for all Boost libraries, for example. Consequently, without some minimum standard for warnings, there may be too much variation.
There should be guidelines on things to avoid when trying to fix warnings. Emil's favorite is to avoid casts because they bypass the implicit type conversion system in the language and can hide problems. I don't agree entirely with his concerns, but there is value in what he says.
We need guidelines that prescribe and others that proscribe to ensure best practice.
I think, you both are right here. Maximum level warnings are simply not practical, at least with compilers I dealt with. I honestly don't understand those who think that warning-free code is somehow more solid than the code which emits warnings. Writing code that emits no warnings on all compilers Boost supports is a nightmare and I would even say that the quality of such code would be worse in some respect. Adding casts, pragmas, removing parameter names and adding conditional compilation to avoid "unsafe" functions - all this makes the code more complicated and harder to maintain and understand. I don't like warnings and I'm for fixing them - but only up to the point when it doesn't hurt the code clarity. This usually amounts up to /W3 on MSVC and default warning settings on GCC. Some warnings, like signed/unsigned comparison and uninitialized variables, often indicate real bugs and should be taken care of. I'd suggest to make a list of such warnings (or warning settings on particular compilers) and try to avoid them in Boost. Note that I'm against making this list of all warnings at the highest levels and as such I'm not offering a solution for those seeking for a warning-free Boost. I think, the list will be quite short, in fact. But by following this guideline we will improve Boost code quality without paying much time and nerves. I think, Paul's Wiki page is a good starting point in this direction. On the original topic: * I don't think that adding the ability to mask out all Boost warnings is of much use. After all, if users are trying to make their code warning-free, they probably want to make the code more safe and bug-free. Hiding warnings in libraries they use (Boost included) looks like a disservice, since the warnings may be valid. * If a user encounters valid warnings with Boost, he should be encouraged to report them back so that we could fix them in Boost code. In case if the warning is spurious and the developer doesn't want to cripple the code to work it around, the user is usually able to mask it away for Boost locally (by pragmas or by warning settings on his particular compiler; on GCC one could even use -isystem). That's why I don't think that adding the policy is a good idea for Boost in general. However, particular library developers may offer this feature of their own libraries, on their free will.

Andrey Semashev wrote:
I honestly don't understand those who think that warning-free code is somehow more solid than the code which emits warnings.
The intended goal is to allow Boost users to focus on warnings from their own code, at whatever warnings level they like. The more warnings Boost code triggers, the more such users will grow to ignore all warnings which means compilers cannot assist them in writing safer code. The suggestion to be able to suppress all warnings from Boost headers does that, with some possibility of suppressing some triggered by user interaction with Boost code that shouldn't be ignored. _____ Rob Stewart robert.stewart@sig.com Software Engineer, Core Software using std::disclaimer; Susquehanna International Group, LLP http://www.sig.com IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

On 30.08.2010 20:59, Stewart, Robert wrote:
Andrey Semashev wrote:
I honestly don't understand those who think that warning-free code is somehow more solid than the code which emits warnings.
The intended goal is to allow Boost users to focus on warnings from their own code, at whatever warnings level they like. The more warnings Boost code triggers, the more such users will grow to ignore all warnings which means compilers cannot assist them in writing safer code.
The suggestion to be able to suppress all warnings from Boost headers does that, with some possibility of suppressing some triggered by user interaction with Boost code that shouldn't be ignored.
As I said, users can already disable all warnings from third party headers. The suggested macro-switch in Boost does little better here, doesn't worth the hassle, IMHO.

Andrey Semashev wrote:
As I said, users can already disable all warnings from third party headers.
I know one can use -isystem with GCC, but how is that done with other compilers? _____ Rob Stewart robert.stewart@sig.com Software Engineer, Core Software using std::disclaimer; Susquehanna International Group, LLP http://www.sig.com IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

On 30.08.2010 21:24, Stewart, Robert wrote:
Andrey Semashev wrote:
As I said, users can already disable all warnings from third party headers.
I know one can use -isystem with GCC, but how is that done with other compilers?
With MSVC (and, probably ICL) you can use pragmas around Boost headers. I don't know about other compilers, but if there are similar tricks for them, they can be applied on user's side just as well as on Boost's side.

Andrey Semashev wrote:
On 30.08.2010 21:24, Stewart, Robert wrote:
Andrey Semashev wrote:
As I said, users can already disable all warnings from third party headers.
I know one can use -isystem with GCC, but how is that done with other compilers?
With MSVC (and, probably ICL) you can use pragmas around Boost headers.
I thought you were implying a simple, -isystem-like approach whereby just using a command line option would silence the warnings.
I don't know about other compilers, but if there are similar tricks for them, they can be applied on user's side just as well as on Boost's side.
That means every user that wants that behavior must create a set of local headers to include before Boost headers in order to get the surrounding pragmas or whatever. That's not very polite, but I suppose if the assumption is that few have that problem/concern, then they ought to pay for the trouble rather than force the Boost maintainers to do so. Unfortunately, Boost libraries vary from release to release, so maintaining a parallel set of headers is rather cumbersome for library users. _____ Rob Stewart robert.stewart@sig.com Software Engineer, Core Software using std::disclaimer; Susquehanna International Group, LLP http://www.sig.com IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

On 08/30/2010 11:00 PM, Stewart, Robert wrote:
Andrey Semashev wrote:
I don't know about other compilers, but if there are similar tricks for them, they can be applied on user's side just as well as on Boost's side.
That means every user that wants that behavior must create a set of local headers to include before Boost headers in order to get the surrounding pragmas or whatever. That's not very polite, but I suppose if the assumption is that few have that problem/concern, then they ought to pay for the trouble rather than force the Boost maintainers to do so. Unfortunately, Boost libraries vary from release to release, so maintaining a parallel set of headers is rather cumbersome for library users.
Well, it doesn't _require_ the headers. The common practice in Windows development is to have StdAfx.h, which is used to generate pch. Most third party headers are included there, so users can simply wrap all Boost includes in the project with pragmas in StdAfx.h. That's what I sometimes do. My point is that the warning-free requirement (at high levels) seems quite specific and, to my mind, quite pointless. Additionally, suppressing all warnings in all Boost headers is (a) compiler-specific, (b) tedious and (c) may not be what the user actually wants. Therefore let the users decide what and how to do about warnings.

On Mon, Aug 30, 2010 at 10:55 PM, Andrey Semashev <andrey.semashev@gmail.com> wrote:
My point is that the warning-free requirement (at high levels) seems quite specific and, to my mind, quite pointless. Additionally, suppressing all warnings in all Boost headers is (a) compiler-specific, (b) tedious and (c) may not be what the user actually wants. Therefore let the users decide what and how to do about warnings.
Here's my suggestion: * We make no requirement on developers that they address warnings * We choose a warning level we're going to test at for each compiler * On our testing pages we publish the number of warnings for each test along with the number of errors * On our guidelines page we publish a list of safe ways to "avoid" various warnings (e.g. use implicit conversions) and perhaps less-safe ways to "suppress" them (e.g. use a cast). -- Dave Abrahams BoostPro Computing http://www.boostpro.com

On Mon, Aug 30, 2010 at 9:46 PM, Dave Abrahams <dave@boostpro.com> wrote:
* On our guidelines page we publish a list of safe ways to "avoid" various warnings
+1 Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Dave Abrahams Sent: Tuesday, August 31, 2010 5:46 AM To: boost@lists.boost.org Subject: Re: [boost] Towards a Warning free code policy proposal
On Mon, Aug 30, 2010 at 10:55 PM, Andrey Semashev <andrey.semashev@gmail.com> wrote:
My point is that the warning-free requirement (at high levels) seems quite specific and, to my mind, quite pointless. Additionally, suppressing all warnings in all Boost headers is (a) compiler-specific, (b) tedious and (c) may not be what the user actually wants. Therefore let the users decide what and how to do about warnings.
I think this is really, really unhelpful. And I think there is enough opinions and evidence that getting rid of warnings makes the code better. So many, perhaps most, people (if not all) believe getting 'warnings free' remains a good objective.
Here's my suggestion:
* We make no requirement on developers that they address warnings We do this now.
* We choose a warning level we're going to test at for each compiler We do this now - but I'd like to see it at W all.
* On our testing pages we publish the number of warnings for each test along with the number of errors We (someone) could do this, but it might be some work to get a warnings count on all systems? (We might more easily be able to get a count != 0).
(But I note that many warnings arise from libraries when they are used by other libraries, for example Boost.Format and Fusion used by Boost.Math. This makes warnings count much less useful) .
* On our guidelines page we publish a list of safe ways to "avoid". various warnings (e.g. use implicit conversions) and perhaps less-safe ways to "suppress" them (e.g. use a cast).
We already have quite a lot on this at https://svn.boost.org/trac/boost/wiki/Guidelines/WarningsGuidelines (but more expert input/correction/improvement is very welcome. You can edit it, or I will handle the editorial bit if that is easier). Paul --- Paul A. Bristow, Prizet Farmhouse, Kendal LA8 8AB UK +44 1539 561830 07714330204 pbristow@hetp.u-net.com

First, a clarification: At Tue, 31 Aug 2010 08:34:31 +0100, Paul A. Bristow wrote: This part is Andrey:
On Mon, Aug 30, 2010 at 10:55 PM, Andrey Semashev <andrey.semashev@gmail.com> wrote:
My point is that the warning-free requirement (at high levels) seems quite specific and, to my mind, quite pointless. Additionally, suppressing all warnings in all Boost headers is (a) compiler-specific, (b) tedious and (c) may not be what the user actually wants. Therefore let the users decide what and how to do about warnings.
I think this is really, really unhelpful.
And I think there is enough opinions and evidence that getting rid of warnings makes the code better.
So many, perhaps most, people (if not all) believe getting 'warnings free' remains a good objective.
And this stuff was posted by me:
Here's my suggestion:
* We make no requirement on developers that they address warnings
We do this now.
Yes.
* We choose a warning level we're going to test at for each compiler
We do this now - but I'd like to see it at W all.
Do we? Was there any formal decision made, and does anything ensure that testers aren't overriding that decision in their xxx-config.jam files?
* On our testing pages we publish the number of warnings for each test along with the number of errors
We (someone) could do this, but it might be some work to get a warnings count on all systems?
It's well-understood technology. CTest does it for example.
(But I note that many warnings arise from libraries when they are used by other libraries, for example Boost.Format and Fusion used by Boost.Math. This makes warnings count much less useful) .
My point in suggesting the warning count is to provide some incentive to clear the warnings. That would happen even for the "transitive warnings" like the ones you describe.
* On our guidelines page we publish a list of safe ways to "avoid". various warnings (e.g. use implicit conversions) and perhaps less-safe ways to "suppress" them (e.g. use a cast).
We already have quite a lot on this at https://svn.boost.org/trac/boost/wiki/Guidelines/WarningsGuidelines (but more expert input/correction/improvement is very welcome. You can edit it, or I will handle the editorial bit if that is easier).
Wow, I didn't even know about this page. Nice work, Paul! OK, then, IMO the status quo is mostly fine except that we have no metrics to help developers know how they're doing on warning suppression. -- Dave Abrahams BoostPro Computing http://www.boostpro.com

On Tue, Aug 31, 2010 at 7:00 AM, David Abrahams <dave@boostpro.com> wrote:
We already have quite a lot on this at https://svn.boost.org/trac/boost/wiki/Guidelines/WarningsGuidelines (but more expert input/correction/improvement is very welcome. You can edit it, or I will handle the editorial bit if that is easier).
Wow, I didn't even know about this page. Nice work, Paul! OK, then, IMO the status quo is mostly fine except that we have no metrics to help developers know how they're doing on warning suppression.
We sort of do, if users don't complain about warnings, all is good. :) Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

On Tue, Aug 31, 2010 at 4:20 PM, Emil Dotchevski <emil@revergestudios.com> wrote:
On Tue, Aug 31, 2010 at 7:00 AM, David Abrahams <dave@boostpro.com> wrote:
IMO the status quo is mostly fine except that we have no metrics to help developers know how they're doing on warning suppression.
We sort of do, if users don't complain about warnings, all is good. :)
:-) -- Dave Abrahams BoostPro Computing http://www.boostpro.com

We already have quite a lot on this at https://svn.boost.org/trac/boost/wiki/Guidelines/WarningsGuidelines (but more expert input/correction/improvement is very welcome. You can edit it, or I will handle the editorial bit if that is easier).
Not "expert" input, but the table under Specific Warnings and Suggested Actions :: Microsoft is barely readable for me (Firefox 3.6.8). Can't the columns in row i have the same width as the columns in row j for all i,j? On the issue of a casting between signed and unsigned types (error 4244 in VC), I am a bit concerned I am missing something. Why is there significant discussion about choosing which cast to make the warning go away? I am labouring under the impression that boost::numeric_cast was invented to do those conversions? Pete

On Tue, 2010-08-31 at 17:06 +0300, Peter Bartlett wrote:
On the issue of a casting between signed and unsigned types (error 4244 in VC), I am a bit concerned I am missing something. Why is there significant discussion about choosing which cast to make the warning go away? I am labouring under the impression that boost::numeric_cast was invented to do those conversions?
numeric_cast will throw if the cast is not safe, and sometimes that is not what you want. There may be legacy design decisions involved which you may not be able to change, such as using negative numbers to indicate special conditions for a variable which is normally unsigned, and the special condition may not indicate an error, but a case you just have to handle separately. --> Mika Heiskanen

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Peter Bartlett Sent: Tuesday, August 31, 2010 3:06 PM To: boost@lists.boost.org Subject: Re: [boost] Towards a Warning free code policy proposal
We already have quite a lot on this at https://svn.boost.org/trac/boost/wiki/Guidelines/WarningsGuidelines (but more expert input/correction/improvement is very welcome. You can edit it, or I will handle the editorial bit if that is easier).
Not "expert" input, but the table under Specific Warnings and Suggested Actions :: Microsoft is barely readable for me (Firefox 3.6.8). Can't the columns in row i have the same width as the columns in row j for all i,j?
Well if the Trac wiki-style can, I'm a novice who has yet to discover it ;-) Any experts out there who know more than I do? But by enlarging and contracting you can at least read everything. Paul --- Paul A. Bristow, Prizet Farmhouse, Kendal LA8 8AB UK +44 1539 561830 07714330204 pbristow@hetp.u-net.com

On 2 September 2010 09:41, Paul A. Bristow <pbristow@hetp.u-net.com> wrote:
Well if the Trac wiki-style can, I'm a novice who has yet to discover it ;-)
Any experts out there who know more than I do?
Just needed to delete the blank lines between rows. They were making each row a separate table. Personally, I wouldn't use a table for the data, it crams too much into a small space. I'd just use a separate page for each compiler. I also noticed that you're using bold text for headers, it's better to use proper headers (using equal signs) to give the page structure. I'll try to clean up the markup later. Daniel

On 2 September 2010 11:20, Daniel James <dnljms@gmail.com> wrote:
Personally, I wouldn't use a table for the data, it crams too much into a small space. I'd just use a separate page for each compiler.
Here's an example of what I mean. https://svn.boost.org/trac/boost/wiki/Guidelines/Warnings/Microsoft Note that the warnings are listed on the right for quick access (this is automatically done from the headers). If you like it, I'll copy and reformat the rest of the warnings. Although I'm not sure if a definition list is the best way to lay out the details. Daniel

[Daniel James]
Here's an example of what I mean. https://svn.boost.org/trac/boost/wiki/Guidelines/Warnings/Microsoft
This should mention that Boost headers should push/disable/pop. If they just disable, then they're disabling that warning for the rest of the translation unit. (Note that push/disable/pop is superior to other schemes such as disable/default, which don't do the right thing.) Stephan T. Lavavej Visual C++ Libraries Developer

On Sep 2, 2010, at 4:26 PM, Stephan T. Lavavej wrote:
[Daniel James]
Here's an example of what I mean. https://svn.boost.org/trac/boost/wiki/Guidelines/Warnings/Microsoft
This should mention that Boost headers should push/disable/pop. If they just disable, then they're disabling that warning for the rest of the translation unit.
Does that work for warnings that occur in template instantiations? Sebastian

[Daniel James]
Here's an example of what I mean. https://svn.boost.org/trac/boost/wiki/Guidelines/Warnings/Microsoft
[STL]
This should mention that Boost headers should push/disable/pop. If they just disable, then they're disabling that warning for the rest of the translation unit.
[Sebastian Redl]
Does that work for warnings that occur in template instantiations?
Unfortunately, not always. STL

On 3 September 2010 00:26, Stephan T. Lavavej <stl@exchange.microsoft.com> wrote:
[Daniel James]
Here's an example of what I mean. https://svn.boost.org/trac/boost/wiki/Guidelines/Warnings/Microsoft
This should mention that Boost headers should push/disable/pop. If they just disable, then they're disabling that warning for the rest of the translation unit.
I didn't include that because I was just making a suggestion about how the warnings could be formatted. The full document is still at: https://svn.boost.org/trac/boost/wiki/Guidelines/WarningsGuidelines Which describes pushing and popping warnings (I'm sure Paul would appreciate any help with this). If we decide to put compiler specific content on separate pages, then the detail will probably go on the individual compiler pages, with an overview on the main page. Daniel

This should mention that Boost headers should push/disable/pop. If they just disable, then they're disabling that warning for the rest of the translation unit.
I didn't include that because I was just making a suggestion about how the warnings could be formatted.
Personally I like the format - looks nice and clear. Just my 2c, John.

On Thu, Sep 2, 2010 at 3:35 PM, Daniel James <dnljms@gmail.com> wrote:
On 2 September 2010 11:20, Daniel James <dnljms@gmail.com> wrote:
Personally, I wouldn't use a table for the data, it crams too much into a small space. I'd just use a separate page for each compiler.
Here's an example of what I mean.
https://svn.boost.org/trac/boost/wiki/Guidelines/Warnings/Microsoft
I think that this would be more helpful if it just listed how each warning responds to various edits instead of suggesting how it should be fixed. For example, the unreferenced formal parameter warning section could look like this: C4100 (Unreferenced formal parameter) - delete the parameter name or add a reference to the parameter in the function: (void)foo; Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

Emil Dotchevski wrote:
On Thu, Sep 2, 2010 at 3:35 PM, Daniel James <dnljms@gmail.com> wrote:
On 2 September 2010 11:20, Daniel James <dnljms@gmail.com> wrote:
Personally, I wouldn't use a table for the data, it crams too much into a small space. I'd just use a separate page for each compiler. Here's an example of what I mean.
https://svn.boost.org/trac/boost/wiki/Guidelines/Warnings/Microsoft
I think that this would be more helpful if it just listed how each warning responds to various edits instead of suggesting how it should be fixed. For example, the unreferenced formal parameter warning section could look like this:
C4100 (Unreferenced formal parameter) - delete the parameter name or add a reference to the parameter in the function: (void)foo;
I thought I remember the latter triggering another warning. I don't remember the exact verbage or compiler. Or does the prefix (void) supress that? Jeff

On 03/09/10 05:23, Jeff Flinn wrote:
C4100 (Unreferenced formal parameter) - delete the parameter name or add a reference to the parameter in the function: (void)foo;
I thought I remember the latter triggering another warning. I don't remember the exact verbage or compiler. Or does the prefix (void) supress that?
could be fixed by having an helper details function like: void unused_param(T const&) {} and do unused_param(oo);

Daniel James wrote:
On 2 September 2010 11:20, Daniel James <dnljms@gmail.com> wrote:
Personally, I wouldn't use a table for the data, it crams too much into a small space. I'd just use a separate page for each compiler.
Here's an example of what I mean.
https://svn.boost.org/trac/boost/wiki/Guidelines/Warnings/Microsoft
Very nice.
Note that the warnings are listed on the right for quick access (this is automatically done from the headers).
That's a helpful result of using headers as you'd suggested.
I'm not sure if a definition list is the best way to lay out the details.
That has the benefit of providing simple, uniform layout which enhances readability. However, just using two boldfaced introductory words to introduce each of two paragraphs -- no indentation, IOW -- might do just as well. _____ Rob Stewart robert.stewart@sig.com Software Engineer, Core Software using std::disclaimer; Susquehanna International Group, LLP http://www.sig.com IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Andrey Semashev wrote:
On 08/30/2010 11:00 PM, Stewart, Robert wrote:
Andrey Semashev wrote:
I don't know about other compilers, but if there are similar tricks for them, they can be applied on user's side just as well as on Boost's side.
That means every user that wants that behavior must create a set of local headers to include before Boost headers in order to get the surrounding pragmas or whatever. That's not very polite, but I suppose if the assumption is that few have that problem/concern, then they ought to pay for the trouble rather than force the Boost maintainers to do so. Unfortunately, Boost libraries vary from release to release, so maintaining a parallel set of headers is rather cumbersome for library users.
Well, it doesn't _require_ the headers. The common practice in Windows development is to have StdAfx.h, which is used to generate pch. Most third party headers are included there, so users can simply wrap all Boost includes in the project with pragmas in StdAfx.h. That's what I sometimes do.
Supposing that's the direction followed, it would be appropriate to have information on the web site about best practices for suppressing all or most warnings from Boost headers in user environments. Thus, you could describe the PCH approach on such a page for the benefit of Windows developers and another could describe the approach needed for other compilers/platforms. That information should be prominently featured for easy discovery.
My point is that the warning-free requirement (at high levels) seems quite specific and, to my mind, quite pointless. Additionally, suppressing all warnings in all Boost headers is (a) compiler- specific, (b) tedious and (c) may not be what the user actually wants. Therefore let the users decide what and how to do about warnings.
There may well be no other way to reach agreement. _____ Rob Stewart robert.stewart@sig.com Software Engineer, Core Software using std::disclaimer; Susquehanna International Group, LLP http://www.sig.com IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Andrey Semashev wrote:
On 30.08.2010 15:12, Stewart, Robert wrote:
Artyom wrote:
IMHO: let library developer decide what to disable and what policy he should use. Developer that respects himself would code the way the code compiles with severe warning level.
Boost is thought of as a whole made of parts. If the parts differ wildly in how things are addressed, the whole suffers. That's why we have high documentation standards for all Boost libraries, for example. Consequently, without some minimum standard for warnings, there may be too much variation.
There should be guidelines on things to avoid when trying to fix warnings. Emil's favorite is to avoid casts because they bypass the implicit type conversion system in the language and can hide problems. I don't agree entirely with his concerns, but there is value in what he says.
We need guidelines that prescribe and others that proscribe to ensure best practice.
I think, you both are right here.
Maximum level warnings are simply not practical, at least with compilers I dealt with. I honestly don't understand those who think that warning-free code is somehow more solid than the code which emits warnings. Writing code that emits no warnings on all compilers Boost supports is a nightmare and I would even say that the quality of such code would be worse in some respect. Adding casts, pragmas, removing parameter names and adding conditional compilation to avoid "unsafe" functions - all this makes the code more complicated and harder to maintain and understand. I don't like warnings and I'm for fixing them - but only up to the point when it doesn't hurt the code clarity. This usually amounts up to /W3 on MSVC and default warning settings on GCC.
This is from the library writer's perspective. What about the potential library user? If I have a code base that compiles cleanly with MSVC at /W4, I really don't like to lower my settings to /W3 or /W2 just because the library should also be compilable by SunStudio or a 10 year old Borland compiler. What do I care? :-) The curse of a portable library falls on a user who's code isn't portable anyway. Bo Persson

On 30.08.2010 21:50, Bo Persson wrote:
This is from the library writer's perspective. What about the potential library user?
That was not limited to the library developer's perspective. I strive for this policy as a library user, too (and as a Boost user, in particular). Although to that end, as a user I also usually write portable code.

----- Original Message ----- From: "Andrey Semashev" <andrey.semashev@gmail.com> To: <boost@lists.boost.org> Sent: Monday, August 30, 2010 6:51 PM Subject: Re: [boost] Towards a Warning free code policy proposal
On the original topic: * I don't think that adding the ability to mask out all Boost warnings is of much use. <snip> That's why I don't think that adding the policy is a good idea for Boost in general. However, particular library developers may offer this feature of their own libraries, on their free will.
Andrey, If I can recall the original topic, what I proposed is something you already do in quite a lot of files in Boost.Expression. Vicente

On 08/30/2010 11:14 PM, vicente.botet wrote:
----- Original Message ----- From: "Andrey Semashev"<andrey.semashev@gmail.com> To:<boost@lists.boost.org> Sent: Monday, August 30, 2010 6:51 PM Subject: Re: [boost] Towards a Warning free code policy proposal
On the original topic: * I don't think that adding the ability to mask out all Boost warnings is of much use. <snip> That's why I don't think that adding the policy is a good idea for Boost in general. However, particular library developers may offer this feature of their own libraries, on their free will.
Andrey,
If I can recall the original topic, what I proposed is something you already do in quite a lot of files in Boost.Expression.
Um... I'm not a maintainer of Boost.Exception. I believe, Emil is the library maintainer.

----- Original Message ----- From: "Andrey Semashev" <andrey.semashev@gmail.com> To: <boost@lists.boost.org> Sent: Tuesday, August 31, 2010 4:46 AM Subject: Re: [boost] Towards a Warning free code policy proposal
On 08/30/2010 11:14 PM, vicente.botet wrote:
----- Original Message ----- From: "Andrey Semashev"<andrey.semashev@gmail.com> To:<boost@lists.boost.org> Sent: Monday, August 30, 2010 6:51 PM Subject: Re: [boost] Towards a Warning free code policy proposal
On the original topic: * I don't think that adding the ability to mask out all Boost warnings is of much use. <snip> That's why I don't think that adding the policy is a good idea for Boost in general. However, particular library developers may offer this feature of their own libraries, on their free will.
Andrey,
If I can recall the original topic, what I proposed is something you already do in quite a lot of files in Boost.Expression.
Um... I'm not a maintainer of Boost.Exception. I believe, Emil is the library maintainer.
Sorry for the mistake. I started to don't understand at all your arguments. Sorry again, Vicente

On 08/27/2010 06:26 PM, vicente.botet wrote:
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>
Switch the logic and I might agree: BOOST_DISABLE_WARNINGS: If defined, disable warnings for all the Boost libraries BOOST_<LIB>_DISABLE_WARNINGS: If defined, disable warnings for a specific library<LIB> Turning off all warnings for boost by default would be madness IMO. After all, the most libraries within boost are under development. Some are pretty new. It is to be expected that some of the code will produce warnings. It is important to have users report them, so that the code in question can be be inspected and possibly fixed. It is like a continuous low-intensity review. The situation with boost warnings is impressive, anyway. In our company we are currently using about 25 boost libraries in our code. And we get no warnings. None. Zero. Zilch. Even though we are trying hard to get them with gcc-4.4: -Wall -Wreorder -Wnon-virtual-dtor -Wno-non-template-friend -Woverloaded-virtual -Wsign-promo -Wextra I am sure, we will stumble upon new warnings some nice day in the not too far away future, but my experience with warnings in boost is very good: a) Most of the time, they are rather easy to fix b) All the time, the respective developer is putting effort into fixing reported warnings for the next release or maybe the one after that. Essentially, the situation is getting better with each and every release of boost. Awesome! It also sets an example for others. But OK, if - Someone simply cannot wait for a warning to get fixed (for instance because a certain warning is driving him mad), - Same someone is either not willing or not able to provide a reasonable solution that takes care of the warning, - Same someone is willing to assume that despite the warning everything is just fine, then (and I'd say only then), that someone would benefit from an option to turn off all warnings. In summary: Having the ability to turn off warnings, might be helpful under certain conditions. But to turn them off by default would be a big mistake IMO. Or, in other words, in contrast to mailing lists, opt-out should be preferred over opt-in when it comes to warnings. Regards, Roland

----- Original Message ----- From: "Roland Bock" <rbock@eudoxos.de> To: <boost@lists.boost.org> Sent: Monday, August 30, 2010 8:32 PM Subject: Re: [boost] Towards a Warning free code policy proposal
On 08/27/2010 06:26 PM, vicente.botet wrote:
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>
Switch the logic and I might agree:
BOOST_DISABLE_WARNINGS: If defined, disable warnings for all the Boost libraries BOOST_<LIB>_DISABLE_WARNINGS: If defined, disable warnings for a specific library<LIB>
I proposed the enabling one as Boost.Exception writen by Andrey Semashev use already this pattern. Anyway, I agree that disabling provides to the user the same functionality and favor the warning tracking. SO +1 for the switch. Vicente
participants (24)
-
Andrey Semashev
-
Artyom
-
Bo Persson
-
Daniel James
-
Dave Abrahams
-
David Abrahams
-
Emil Dotchevski
-
Jeff Flinn
-
Jeffrey Lee Hellrung, Jr.
-
Jens Finkhäuser
-
Joel Falcou
-
John Maddock
-
Mathias Gaunard
-
Mika Heiskanen
-
Nevin Liber
-
Paul A. Bristow
-
Peter Bartlett
-
Raymond Wan
-
Robert Ramey
-
Roland Bock
-
Sebastian Redl
-
Stephan T. Lavavej
-
Stewart, Robert
-
vicente.botet