Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

visual studio - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...