我正在使用 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/