禁用警告c4702似乎不适用于VS 2012 [英] disable warning c4702 seems not work for VS 2012
问题描述
我有一些测试代码,这些代码是我在其余代码的前面添加的,因此其余代码将永远无法在测试中实现. 由于我设置了警告级别4,因此导致出现c4702:无法访问代码警告
I have some code for testing that i added upfront the rest of the code, so the rest would never be reached in the test. Since i have warning level 4 set, this results in an c4702: unreachable-code warning
我试图这样禁用:
//do something
return 0;
/*-------------------------------------------------------------------------*/
#pragma warning(disable: 4702)
//real code
但是编译器仍然抱怨.而且因为我已将每个警告都视为错误,所以不会编译...
but the compiler still moans. And because i have set to treat every warning as an error, this won't compile...
我正在使用Visual Studio 2012 Premium ...
I am using Visual Studio 2012 Premium...
任何帮助将不胜感激.
推荐答案
您可能只需要将编译指示放在受影响的函数的开始之前而不是内部.
You maybe just need to place the pragma before the start of the affected function rather than inside it.
从 MSDN文档 :
对于与代码生成相关联的4700-4999范围内的警告编号,当编译器遇到某个函数的大括号时,该警告的状态将对该功能的其余部分生效.在函数中使用警告编译指示来更改数字大于4699的警告状态仅在函数结束后生效.
For warning numbers in the range 4700-4999, which are the ones associated with code generation, the state of the warning in effect when the compiler encounters the open curly brace of a function will be in effect for the rest of the function. Using the warning pragma in the function to change the state of a warning that has a number larger than 4699 will only take effect after the end of the function.
例如:
#pragma warning(push)
#pragma warning(disable: 4702)
bool Do() {
return true;
return true; // No warning generated
#pragma warning(pop)
}
bool DoDo() {
return true;
return true; // Generates C4702
}
这篇关于禁用警告c4702似乎不适用于VS 2012的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!