Disable single warning error

Cookie picture Cookie · Aug 23, 2011 · Viewed 136.7k times · Source

Is there a way to disable just a single warning line in a cpp file with visual studio?

For example, if I catch an exception and don't handle it, I get error 4101 (unreferenced local variable). Is there a way to ignore this just in that function, but otherwise report it in the compilation unit? At the moment, I put #pragma warning (disable : 4101) at the top of the file, but that obviously just turns it off for the whole unit.

Answer

Andreas Brinck picture Andreas Brinck · Aug 23, 2011
#pragma warning( push )
#pragma warning( disable : 4101)
// Your function
#pragma warning( pop )