如何解决第三方库中的C4505警告问题?

Bil*_*eal 12 c++ crypto++ visual-c++

我有一个使用Crypto ++进行一些散列函数的项目.最近,我决定清理一下并在MSVC++上使用警告级别4.

这是我的源代码:

#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)
Run Code Online (Sandbox Code Playgroud)

尽管如此disable: 4505,我仍然得到这个警告:

c:\cppdev\cryptopp561\cryptopp\misc.h(548): warning C4505: 'CryptoPP::StringNarrow' : unreferenced local function has been removed
Run Code Online (Sandbox Code Playgroud)

而我的项目没有建立.

我该如何解决这个问题?基本上,我只想禁用第三方代码的警告; 如果我可以避免这样做,我不想编辑cryptopp本身来修复错误.

Tob*_*que 20

编译器只能在完成解析编译的源文件后才能确定未引用的函数.将相应的#pragma disable移出推/弹范围,使其在文件末尾仍然有效:

#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
Run Code Online (Sandbox Code Playgroud)

  • 这会禁用我的代码警告,而不仅仅是第三方代码. (5认同)
  • 额外的间接水平解决了每个问题.那是一匹适合的老马,写一个包装纸. (5认同)
  • 根据MS,使用pragma无法完成:http://support.microsoft.com/kb/947783在这种特殊情况下,您可以通过这种方式使编译器静音 - 但这可能无法在整个地方工作: void useUnreferenced(){void*dummyReferenceStringNarrow = CryptoPP :: StringNarrow; (void)dummyReferenceStringNarrow; } (2认同)