Boost logo

Boost Users :

From: Joaquín Mª López Muñoz (joaquin_at_[hidden])
Date: 2007-03-20 13:54:53


Gottlob Frege ha escrito:

> On 3/16/07, Joaquín Mª López Muñoz <joaquin_at_[hidden]> wrote:
> > Hello Andrew,
> >
> > Andrew Holden ha escrito:
> >
> > > Joaquín Mª López Muñoz wrote:
> > > >
> > > > Filip Konvi?ka ha escrito:
> > > > >
> > > > > Aye, I got the following warning that I could not get rid of (VC 7.1)
> > > > >
> > > > > C:\Boost\include\boost-1_33_1\boost\functional\hash\hash.hpp(132) :
> > > > > warning C4267: 'argument' : conversion from 'size_t' to 'unsigned int',
> > > > > possible loss of data
> > > >
> > > > [...]
> > > >
> > > > Looks like an overzealous or simply misguided warning. Can you please try
> > > > the following?
> > > >
> > > > [...]
> > > >
> > > > Same warning? If so, you might ask for inclusion of a suitable #pragma
> > > > warning(disable...) to the Boost.Hash author.
> > >
> > > Depending on your concern for portability, you might not want to dismiss this
> > > warning. VC 7.1 and 8.0 provide it as part of their 64 bit portability warnings
> > > (size_t will be 64 bits wide on 64-bit Windows, while unsigned int will remain
> > > 32 bits). A better way to eliminate the warning might be to switch off the
> > > 64 bit portability warnings in your project options.
> >
> > I'm not advocating that the warning be completely disabled, but only in a
> > selective manner inside Boost.Hash code by using #pragma warning(push) and
> > #pragma warning(pop):
> >
> > // boost/hash/hash.hpp
> > #pragma warning(push)
> > #pragma warning(disable:4267)
> > ...
> > #pragma warning(pop)
> >
>
> Maybe it would be better if boost::hash included a size_t version:
>
> inline std::size_t hash_value(std::size_t v)
> {
> return v;
> }
>
> If necessary, in cases where std::size_t == unsigned int, it could
> probably use is_same<T,U> to make sure both versions didn't exist and
> cause warnings/errors.

Hello Tony, this does not work, as VC 8.0 (and I guess VC 7.1 too) treats
(in 32 bit) std::size_t and unsigned int as the very same type except for
/Wp64 diagnosis purposes. AFAICS you cannot even distinguish std::size_t
from unsigned int with any template machinery, however smart --which
is fine after all, since the standard mandates that std::size_t be a typedef
of one of the fundamental integer types, thus ruling out the posibility that
std::size_t is its own separate type.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net