Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable warning c4702 seems not work for VS 2012

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.

like image 525
Juarrow Avatar asked Sep 12 '12 02:09

Juarrow


1 Answers

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
}
like image 191
Fraser Avatar answered Sep 19 '22 15:09

Fraser