为什么我无法在win64上编译带有boost 1.54的VS2012 C++代码
Why I fail to compile VS2012 C++ code with boost 1.54 over win64?
我有一个使用VS2010和boost 1_54_0版本编译的win64应用程序,一切如预期。
我现在正在将应用程序转移到一个新的平台,该平台需要VS2012编译的库。当试图用VS2012编译boost时(稍后链接到我的项目中),我得到了以下编译器警告:
1>c:<my_path>boostboost_1_54_0boostfunctionalhashhash.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>boostboost_1_54_0boost/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>boostboost_1_54_0boost/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;
}
第#176
行是for
语句:for(unsigned int i = length * size_t_bits; i > 0; i -= size_t_bits)
。
现在我似乎不明白编译器到底在警告我什么?如果条件是i>=0
,这是有意义的(根据MSDN对C6295的解释),但for
语句逻辑对我来说还可以
此警告的根本原因是什么?如何解决它?
另外,由于我的应用程序使用了警告级别4(警告被视为错误)-由于这个警告,我无法编译应用程序。
感谢
这是在Boost中修复的:https://svn.boost.org/trac/boost/ticket/8568.
我建议更新到Boost 1.55,在本地修补Boost副本,或者使用/wd6295
或Boost includes周围的pragma禁用该特定警告。
尽管在这种情况下可能不适用于您,但这就是为什么在已发布的源代码中包含的构建脚本中强制警告=错误通常是一件坏事:新的编译器版本会添加新的警告。
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- boost::进程间消息队列引发错误
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- cmake如何在fedora工作站中找到boost静态库包
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- Boost Graph Library,修复节点大小
- 什么是"#include <boost/functional/hash.hpp> "?
- 基于boost的程序的静态链接——zlib问题
- C++:如何在CLion IDE中安装Boost
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 如何在boost beast http请求中设置http头
- Boost Spirit,获取迭代器内部语义动作
- boost::asio::steady_timer()与sleep()我应该使用哪一个
- boost::asio如何生成多个协同程序,然后加入它们
- 当我尝试使用 sstream 和分面将 Boost Time_duration转换为字符串时,我没有得到所需的格式
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- Boost 1_52内部版本VS2012失败
- 在VS2012项目上编译Boost C++库
- 通过值返回boost ublas矩阵,仅在vs2012的发布配置中工作
- 为什么我无法在win64上编译带有boost 1.54的VS2012 C++代码