Visual Studio 2012 C++使用Boost Signal2编译错误

hea*_*ude 10 c++ boost visual-studio boost-signals2

我正在使用带有以下Boost Signals2代码的Visual Studio 2012 Ultimate:https://github.com/cfobel/boost_signals2/blob/master/hello_world_0.cpp 它会生成以下错误:

c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory(348): error C4996: 'std::_Uninitialized_copy0': 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 11.0\vc\include\xmemory(333) : see declaration of 'std::_Uninitialized_copy0'
1>          c:\libraries\boost_1_52_0\boost\signals2\detail\auto_buffer.hpp(192) : see reference to function template instantiation '_FwdIt std::uninitialized_copy<I,boost::variant<T0_,T1>*>(_InIt,_InIt,_FwdIt)' being compiled
Run Code Online (Sandbox Code Playgroud)

此代码与Visual Studio 2012 C++不兼容吗?它还可以安全使用吗?最后,如何按照建议进行更改?谢谢

Pra*_*ian 11

C4996是关于使用已标记为已弃用的函数的警告.既然您将其视为错误,也许您已Treat Warning as Error (/WX)启用该选项?

错误消息本身描述了禁用此方法的方法.将_SCL_SECURE_NO_WARNINGS符号添加到项目的预处理器定义中.

  • 非常有用的答案,但没有触及*"它是否仍然安全使用?"*.换句话说,boost :: signals2会引起这个警告,人们应该关注它吗? (5认同)
  • @Praetorian:令人讨厌的是,MSVC的警告可能不会被抑制,如果你只是将boost头文件包裹起来`#pragmas`,因为它后来在模板实例化网站上归咎于`xmemory`,而这通常是由一个早期导入没有pragma包装器.它很快就变成了一场打鼹鼠的游戏. (3认同)
  • @sgryzko没有一般答案*是否安全*,这取决于有问题的代码.代码是否有可能导致缓冲区溢出的错误?如果是,那么MSVC功能可能会更好.如果不是,那么`std :: uninitialized_copy`是绝对安全的.在你希望能够在多个编译器上编译的任何代码中几乎无法避免这些警告,因为MSVC甚至会抱怨像`std :: copy`这样的东西(它希望你使用`std :: _ Copy_s`). (2认同)