如何在VS2013社区中禁用警告C4927

How to disable warning C4927 in VS2013 Community

本文关键字:警告 C4927 社区 VS2013      更新时间:2023-10-16

我在项目中收到以下警告:

warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied while calling the constructor 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(const _Elem *)'
      with
      [
          _Elem=char
      ]
      C:Program Files (x86)Microsoft Visual Studio 12.0VCincludexstring(778) : see declaration of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string'

我理解为什么会发生这种情况,只是无法抑制它。我已尝试将它添加到项目设置中的"禁用特定警告"列表中,还将警告级别设置为"关闭所有警告"(/W0),但警告仍然存在。有人对如何隐藏信息有什么建议吗?

您可以使用#pragma warning直接在代码中控制Visual Studio警告(https://msdn.microsoft.com/en-us/library/2c8f766e.aspx)。如果你想让一行的警告静音,你可以在该行之前立即放置以下内容:

#pragma warning (suppress: 4927)
line-that-causes-warning-4927

您也可以从#pragma之后的任何点禁用它,方法是使用"disable"而不是"suppress"。然而,正如评论所建议的那样,最好实际修复警告,因为它可能会导致程序出现问题。