siv*_*udh 46 c++ boost compiler-warnings
我有一个简单的C++与Boost像这样:
#include <boost/algorithm/string.hpp>
int main()
{
std::string latlonStr = "hello,ergr()()rg(rg)";
boost::find_format_all(latlonStr,boost::token_finder(boost::is_any_of("(,)")),boost::const_formatter(" "));
Run Code Online (Sandbox Code Playgroud)
这很好用; 它取代了每次出现的(),用""
但是,我在编译时收到此警告:
我正在使用MSVC 2008,Boost 1.37.0.
1>Compiling...
1>mainTest.cpp
1>c:\work\minescout-feat-000\extlib\boost\algorithm\string\detail\classification.hpp(102) : warning C4996: 'std::copy': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2576) : see declaration of 'std::copy'
1> c:\work\minescout-feat-000\extlib\boost\algorithm\string\classification.hpp(206) : see reference to function template instantiation 'boost::algorithm::detail::is_any_ofF<CharT>::is_any_ofF<boost::iterator_range<IteratorT>>(const RangeT &)' being compiled
1> with
1> [
1> CharT=char,
1> IteratorT=const char *,
1> RangeT=boost::iterator_range<const char *>
1> ]
1> c:\work\minescout-feat-000\minescouttest\maintest.cpp(257) : see reference to function template instantiation 'boost::algorithm::detail::is_any_ofF<CharT> boost::algorithm::is_any_of<const char[4]>(RangeT (&))' being compiled
1> with
1> [
1> CharT=char,
1> RangeT=const char [4]
1> ]
Run Code Online (Sandbox Code Playgroud)
我当然可以禁用警告
-D_SCL_SECURE_NO_WARNINGS
Run Code Online (Sandbox Code Playgroud)
但在我发现错误之前,我有点不愿意这样做,或者更重要的是,如果我的代码不正确.
jal*_*alf 52
没什么值得担心的.在MSVC的最后几个版本中,他们已经进入完全安全 - 偏执模式.std::copy与原始指针一起使用时发出此警告,因为如果使用不当,可能会导致缓冲区溢出.
它们的迭代器实现执行边界检查以确保不会发生这种情况,从而导致显着的性能成本.
所以随意忽略警告.这并不意味着您的代码有任何问题.它只是说,如果你的代码有问题,那么坏事就会发生.发出警告是一件奇怪的事情.;)
Biz*_*rck 25
您还可以在特定标头中禁用此警告:
#if defined(_MSC_VER) && _MSC_VER >= 1400
#pragma warning(push)
#pragma warning(disable:4996)
#endif
/* your code */
#if defined(_MSC_VER) && _MSC_VER >= 1400
#pragma warning(pop)
#endif
Run Code Online (Sandbox Code Playgroud)
Blu*_*ron 19
如果您对禁用此错误感到安全:
"-D_SCL_SECURE_NO_WARNINGS"
警告来自Visual Studio从MSVC 8.0开始引入的非标准"安全"库检查.微软已经确定了"具有潜在危险"的API,并且已经注意到了阻止其使用的警告.虽然技术上可以以不安全的方式调用std :: copy,但是1)接收此警告并不意味着你这样做,并且2)正常情况下使用std :: copy并不危险.
| 归档时间: |
|
| 查看次数: |
26001 次 |
| 最近记录: |