Search code examples
visual-studio-2008suppress-warnings

Disable warnings in Visual Studio 2008


Env: Visual Studio Warning Level is set to 4, Code in the only file in solution:

#pragma warning( push )
#pragma warning( disable: 4503 )
#pragma warning( disable: 4702 )
#include <boost/property_tree/ptree.hpp>
#pragma warning ( pop ) //mark

#include "iostream"

int main()
{
boost::property_tree::ptree pt;
for( boost::property_tree::ptree::const_iterator it = pt.begin();
     it != pt.end();
     ++it )
    {
    std::cout << it->second.data() << '\n';
    }

return 0;
}

Problem: Warning 4503 still show up when compiling. Something else I have tried:

  1. put the line with '//mark' as last line of the app, no effect.
  2. if I use #pragma warning( disable: 4503 4702 ) without push/pop, it works, but it affects what's been compiled afterwards for whole solution, even I put #pragma warning( default: xx ) somewhere, it doesn't seem to set the warning back to default status.

Who knows why this is happening and what's the best solution for suppressing warnings in visual studio. cheers.


Solution

  • found answer from here:http://connect.microsoft.com/VisualStudio/feedback/details/442051/cannot-suppress-warning-in-template-function

    Roughly, the reason is because the warnings generated in my code while not in header file, because it's template. If the code is generated in header files, it would work.