2014-04-23 54 views
0

我有一個使用VS2010和boost 1_54_0版本編譯的win64應用程序 - 一切都按預期工作。爲什麼我不能在win64上編譯VS2012 C++代碼並使用boost 1.54?

我現在轉移應用到一個新的平臺,這需要VS2012編譯庫。 試圖編譯與VS2012提升(以後鏈接到我的項目)時,我得到以下編譯器警告:

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>代表自己的計算機上的本地路徑,因此這可以忽略不計)

環視hash.hpp文件的行#176(例如) - 我看到了以下

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; 
    } 

線#176for聲明:for(unsigned int i = length * size_t_bits; i > 0; i -= size_t_bits)

現在我似乎並不準確瞭解編譯器警告我?如果條件爲i>=0這有意義(作爲C6295的MSDN的解釋),但for陳述邏輯看上去沒給我。

這是什麼警告的根本原因是什麼?如何解決它?

P.S.因爲我的應用程序使用警告級別4(警告視爲錯誤) - 由於此警告,我無法編譯我的應用程序。

感謝

+0

大概長度將對於這種情況是0。 boost :: ulong_long_type和std :: size_t是什麼類型? –

+0

代碼分析警告本質上是胡思亂想。我猜想對於不是1的遞減是不滿意的。因此,如果起始值不能被遞減整除,技術上可以永久循環。當然,只要乘法不會溢出。只需禁用警告。 –

回答

1

這是固定的升壓:https://svn.boost.org/trac/boost/ticket/8568

我建議升級到Boost 1.55,修補你的Boost localy副本,或者使用/wd6295或關於Boost的編譯指示包括禁用該特定警告。

雖然也許並不適用於你在這種情況下,這是一個原因,迫使警告=中所含的發佈源構建腳本錯誤一般是一件壞事:新的編譯器版本中增加新的警告。