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

c++ - How can I work around warning C4505 in third party libraries?

I've got a project that uses Crypto++ for a few hashing functions. Recently, I decided to clean things up a bit and use warning level 4 on MSVC++.

Here's what my source looks like:

#pragma warning(push)
#pragma warning(disable: 4100) //Unreferenced formal parameter
#pragma warning(disable: 4244) //Conversion, possible loss of data
#pragma warning(disable: 4512) //Assignment operator could not be generated
#pragma warning(disable: 4127) //Conditional expression is constant
#pragma warning(disable: 4505) //Unreferenced local function has been removed
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
#include <cryptopp/md5.h>
#include <cryptopp/sha.h>
#pragma warning(pop)

Despite disable: 4505, I still get this warning:

c:cppdevcryptopp561cryptoppmisc.h(548): warning C4505: 'CryptoPP::StringNarrow' : unreferenced local function has been removed

and my project does not build.

How can I work around this? Basically, I'd just like to disable the warning for third party code; I don't want to be editing cryptopp itself to fix the error if I can avoid doing so.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

The compiler can only determine unreferenced functions after it finished parsing the compiled source file. Move the corresponding #pragma disable out of the push/pop scope so it will still be in effect at the end of the file:

#pragma warning(push)
#pragma warning(disable: 4100) //Unreferenced formal parameter
#pragma warning(disable: 4244) //Conversion, possible loss of data
#pragma warning(disable: 4512) //Assignment operator could not be generated
#pragma warning(disable: 4127) //Conditional expression is constant
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
#include <cryptopp/md5.h>
#include <cryptopp/sha.h>
#pragma warning(pop)
#pragma warning(disable: 4505) //Unreferenced local function has been removed

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

...