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
118 views
in Technique[技术] by (71.8m points)

c++ - Is there a way to disable all warnings with a pragma?

I've started a new project and have decided to make sure it builds cleanly with the /Wall option enabled. The only problem is not all 3rd party libraries (like boost) compile without warnings, so I've resorted to doing this in a shared header:

#pragma warning(push)

#pragma warning(disable:4820)
#pragma warning(disable:4619)
#pragma warning(disable:4668)
#pragma warning(disable:4625)
#pragma warning(disable:4626)
#pragma warning(disable:4571)
#pragma warning(disable:4347)
#pragma warning(disable:4640)
#pragma warning(disable:4365)
#pragma warning(disable:4710)
#pragma warning(disable:4820)
#pragma warning(disable:4350)
#pragma warning(disable:4686)
#pragma warning(disable:4711)
#pragma warning(disable:4548)

#include <boost/array.hpp>
#include <boost/assert.hpp>
#include <boost/assign.hpp>
#include <boost/bind.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
#include <boost/function.hpp>
#include <boost/integer.hpp>
#include <boost/optional.hpp>
#include <boost/regex.hpp>
#include <boost/smart_ptr.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/utility.hpp>
#include <boost/variant.hpp>

#pragma warning(pop)

This works well enough, but every time I add new boost headers I have to add whatever warnings they generate to the list. Is there a way to say disable all warnings for this stretch of code?

question from:https://stackoverflow.com/questions/525677/is-there-a-way-to-disable-all-warnings-with-a-pragma

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

1 Answer

0 votes
by (71.8m points)

You can push/pop a low level of warning, like this:

#pragma warning(push, 0)        

#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
// ...

#pragma warning(pop)

But know that it's not possible to disable all warnings. For example, some linker warnings are impossible to turn off.


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

...