disable warning c4702 seems not work for VS 2012

寵の児 提交于 2019-11-28 02:52:54

问题


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

I tried disabling like this:

//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...

I am using Visual Studio 2012 Premium...

Any help would be gladly appreciated.


回答1:


You maybe just need to place the pragma before the start of the affected function rather than inside it.

From the MSDN docs:

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.

So for example:

#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
}


来源:https://stackoverflow.com/questions/12380603/disable-warning-c4702-seems-not-work-for-vs-2012

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!