c++ - 在 Visual Studio 2019 中本地禁用 "Treat Warnings As Error"配置

标签 c++ visual-studio

我正在使用 Visual Studio 2019 中启用的“将警告视为错误”选项。 我想在代码中的某些部分禁用此选项 - 这样仍然会出现警告,但不会被视为错误。我希望有一些#pragma 可以用于此目的。

我知道 #pragma warning(disable : N) 可以用来完全消除警告报告,但我仍然想看到警告,只是不希望该特定代码块的编译失败。当然,在其他地方,它应该按照预期在警告时产生错误。

最佳答案

(From the comments): The option of "Treat Warnings As Error" is something we want to use in our codebase, but there are some warnings which seem to be more troublesome to resolve, so we want to temporarily allow the code to still be compilable, but still show these warnings as regular warnings (as a reminder)

我不相信您在问题中要求的事情是可能的。

幸运的是,你所说的你想要的东西和你要求的东西并不相同。

MSVC 公开 #pragma message( message-string ) 选项 (link)

首先,启用警告作为错误。

接下来,对于您今天无法摆脱的警告,请像您已经知道的那样执行#pragma warning(disable : N),并同时使用# pragma message (__FILE__ "["STRING(__LINE__) "]: WARNING HERE") 或任何适合您的用例的消息。

这将允许您使用警告作为错误进行编译,以防止将来出现警告并保留当前问题点的提醒。

关于c++ - 在 Visual Studio 2019 中本地禁用 "Treat Warnings As Error"配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76198811/

相关文章:

c++ - wxScrolledWindow 添加和删除元素

c++ - 使用 boost 序列化 std::unordered_map < int, std::unordered_set<int>>

c++ - 不存在从 “cv::Mat”到 “IplImage”的合适的用户定义转换

visual-studio - 为什么在 IIS7 中调试总是超时?

visual-studio - 自从VS 11安装以来,导航栏不见了

c++ - 我怎么知道我是唯一打开文件句柄的人?

c++ - 在 OSX 上使用 PortAudio 写入 fifo 并使用 ffmpeg 读取

c++ - 我无法获得在 C++ 中工作的设置精度

.net - 如何开始使用单声道分析器 2.8?

visual-studio - Visual Studio 2013 构建后事件始终显示资源管理器