Pergunta

I have a win64 application compiled using VS2010 and boost 1_54_0 version - everything works as expected.

i'm now transferring the application to a new platform which requires VS2012 compiled libraries. when trying to compile boost with VS2012 (to later link into my project) i get the following compiler warning:

 1>c:\<my_path>\boost\boost_1_54_0\boost\functional\hash\hash.hpp(176): warning C6295: Ill-defined for-loop:  'unsigned int' values are always of range '0' to '4294967295'.  Loop executes infinitely.
 1>C:\<my_path>\boost\boost_1_54_0\boost/functional/hash/hash.hpp(201) : see reference to function template instantiation 'size_t boost::hash_detail::hash_value_unsigned<T>(T)' being compiled
 1>          with
 1>          [
 1>              T=boost::ulong_long_type
 1>          ]
 1>          C:\<my_path>\boost\boost_1_54_0\boost/functional/hash/hash.hpp(439) : see reference to function template instantiation 'boost::hash_detail::enable_hash_value::type boost::hash_value<boost::ulong_long_type>(T)' being compiled
 1>          with
 1>          [
 1>              T=boost::ulong_long_type
 1>          ]

(<my_path> represent the local path on my development machine, so this can be ignored)

looking around the hash.hpp file at lines #176 (for example) - i see the following

    template <class T>
    inline std::size_t hash_value_unsigned(T val)
    {
         const int size_t_bits = std::numeric_limits<std::size_t>::digits;
         // ceiling(std::numeric_limits<T>::digits / size_t_bits) - 1
         const int length = (std::numeric_limits<T>::digits - 1)
             / size_t_bits;

         std::size_t seed = 0;

         // Hopefully, this loop can be unrolled.
         for(unsigned int i = length * size_t_bits; i > 0; i -= size_t_bits)
         {
             seed ^= (std::size_t) (val >> i) + (seed<<6) + (seed>>2);
         }
         seed ^= (std::size_t) val + (seed<<6) + (seed>>2);

         return seed;
    }

Line #176 is the for statement: for(unsigned int i = length * size_t_bits; i > 0; i -= size_t_bits).

Now i don't seem to understand what exactly the compiler warns me? if the condition was i>=0 this make sense (as of MSDN explanation of C6295) but the for statement logic looks ok to me.

What is the root cause of this warning? how to workaround it?

P.S. as my application uses warning level 4 (warning treated as error) - i can't compile my application due to this warning.

Thanks

Foi útil?

Solução

This was fixed in Boost: https://svn.boost.org/trac/boost/ticket/8568.

I suggest updating to Boost 1.55, patching your copy of Boost localy, or disabling that specific warning using /wd6295 or pragma's around Boost includes.

Although maybe not applicable to you in this case, this is a reason that forcing warnings=errors in build scripts contained in released sources is generally a bad thing: new compiler releases add new warnings.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top