C ++提升:这是什么警告的原因是什么? [英] C++ Boost: what's the cause of this warning?

查看:255
本文介绍了C ++提升:这是什么警告的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的C ++有这样的提升:

I have a simple C++ with Boost like this:

#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(" "));

这工作正常;它取代()的每次出现,着有

This works fine; it replaces every occurrence of ( ) , with a " "

不过,我在编译时得到这样的警告:

However, I get this warning when compiling:

我使用MSVC 2008年,升压1.37.0。

I'm using 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>        ]

我可以肯定使用禁用警告

I could certainly disable the warning using

-D_SCL_SECURE_NO_WARNINGS

但我有点舍不得这样做之前,我找出什么是错的,或者更重要的是,如果我的code不正确。

but I'm a bit reluctant to do that before I find out what's wrong, or more importantly if my code is incorrect.

推荐答案

有什么可担心的。在MSVC的最后几个版本,他们已经走了充分的安全偏执模式。 的std ::复制的问题时,用它与原始指针,因为的使用时不正确的,它会导致缓冲区溢出此警告。

It is nothing to worry about. In the last few releases of MSVC, they've gone into full security-paranoia mode. std::copy issues this warning when it is used with raw pointers, because when used incorrectly, it can result in buffer overflows.

他们的迭代器实现执行边界检查,以确保不会发生这种情况,在显著的性能开销。

Their iterator implementation performs bounds checking to ensure this doesn't happen, at a significant performance cost.

可以随意忽略警告。这并不意味着有什么不对您的code。它只是说的如果的有什么不对您的code,那么不好的事情会发生。
这是发出关于警告一件奇怪的事。 ;)

So feel free to ignore the warning. It doesn't mean there's anything wrong with your code. It is just saying that if there is something wrong with your code, then bad things will happen. Which is an odd thing to issue warnings about. ;)

这篇关于C ++提升:这是什么警告的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆