Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2006-06-27 07:40:19


Paul Bristow wrote:
> I have raised this issue before, inconclusively, but the question has now
> become more urgent now that I am packaging some math functions produced by
> John "Doing the Impossible" Maddock.

I am also interested in warning free (or at the very least, warning minimal) code.

> IMO Boost-worthy code should be able to be compiled in strict mode, for MSVC
> level 4, without producing a blizzard of warnings.

Agreed.

> Including a list of warnings that the authors of the library consider
> unhelpful, and in some cases, unfixable (specifically the warning
> "conditional expression is constant. ")
>
> by using, for example
>
> #ifdef _MSC_VER
> # pragma warning(disable: 4127) // conditional expression is constant.
> # pragma warning(disable: 4100) // unreferenced formal parameter.
> # pragma warning(disable: 4512) // assignment operator could not be
> generated.
> # pragma warning(disable: 4996) // 'std::char_traits<char>::copy' was
> declared deprecated.
> // needed ifndef _SCL_SECURE_NO_DEPRECATE or == 0
> // #define _SCL_SECURE_NO_DEPRECATE = 1 // Avoid C4996 warning.
> // #define _SCL_SECURE_NO_DEPRECATE = 0 // get C4996 warning.
> #endif
>
> is fine for that package, but also supresses these warnings for other code,
> which users rightly object to.

Indeed. What's even more annoying is that the Microsoft STL implementation
produces warnings as well!

> Pushing and poping warning levels is VERY tedious, and almost impractiable,
> and doesn't help non-MSVC platforms.
>
> What is the best way to deal with this?

There is the possibility of doing:

#ifndef BOOST_FOO
#define BOOST_FOO

#include <boost/something.hpp>

#include <boost/disable_warnings.hpp>

namespace boost { ... }

#include <boost/enable_warnings.hpp>

#endif

I know that this isn't ideal, but would help support other platforms and be
conststent - e.g. it would allow new warnings to be disabled if/when they
arise. However, it will affect nearly all of Boost.

> Is it to provide for MSVC includable files, say math_strict.hpp,
> test_strict.hpp, filesystem_strict.hpp ... containing the above (tailored
> for the library, if necessary)?
>
> What about other platforms?

Metrowerks CodeWarrior is very annoying in strict (all warnings) mode
and will complain about its standard library to the point where you just
want to go back to the normal warning level! I am not sure about other
compilers.

NOTE: Instead of disabling the warnings, you can remove the warning by
updating the code. For example:

void foo( int bar ){} // unreferenced parameter
void foo( int bar ){ bar; } // no warning!

case 10: return 10; break; // unreachable code
                                ^^^^ remove break; to prevent the warning

bool foo(){ BOOL bar = TRUE; return bar; } // performance warning
bool foo(){ BOOL bar = TRUE; return bar != FALSE; } // no warning

int foo(){ long bar = 10l; return bar; } // conversion warning
int foo(){ long bar = 10l; return int( bar ); } // conversion warning

class foo
{
   bar & m_bar;
   foo( bar & b ): m_bar( b ){}

   // disable the no default compiler assignment operator warning:
   inline foo & operator=( const foo & );
};

Doing these will remove a lot of the warnings in the code without
requiring them being disabled.

I am not sure about other compilers, but I assume that similar
things will apply there.

The deprecated warnings are a major pain. Consider:

   std::copy( first, last, dest );

This will not produce warnings with std::vector, etc. However,
if you use char * it will produce:

   std::_Copy_impl was declared deprecated

Huh! This is because std::copy will use memcpy for POD types
and memcpy (and thus the internal implementation function)
is deprecated! This is worse if std::copy is used in a template
class/function you implement that could use POD types like
the above, so is hard to write warning free. I also doubt
disabling warnings will work here, because the warning will
be generated at the point of instantiation!

- Reece
_________________________________________________________________
Try Live.com - your fast, personalized homepage with all the things you care about in one place.
http://www.live.com/getstarted


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