Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including Crypto++ headers disables warnings #793

Closed
espindola opened this issue Jan 30, 2019 · 5 comments
Closed

Including Crypto++ headers disables warnings #793

espindola opened this issue Jan 30, 2019 · 5 comments

Comments

@espindola
Copy link

espindola commented Jan 30, 2019

Given a test file with just

static void foo() {}

gcc -Wall will print

warning: ‘void foo()’ defined but not used [-Wunused-function]

But if I add

#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
#include <cryptopp/md5.h>

No waning is printed. This is because of the following in cryptopp/config.h.

#pragma GCC diagnostic ignored "-Wunused-function"
@noloader
Copy link
Collaborator

noloader commented Jan 31, 2019

Thanks @espindola,

For the library, it is a "pick your poison". If we don't use -Wno-unused-function then we catch multiple warnings due to unused functions like NumericLimitsMax and StringNarrow. That generates multiple user bug reports.

If we silence the warning, then we get your bug reports.

In this case I think the best thing to do is for you to remove the pragma from config.h. Then you can catch them.

You might also consider asking GCC to move -Wunused-function to -Wextra. Unused functions in C++ header files does not seem like the kind of warning that needs to be flagged. It is expected in C++ project files.


Here's a sampling of your preferred configuration. In the build below I removed the pragma from config.h.

$ CXXFLAGS="-DNDEBUG -g2 -O3 -Wall" make -j 4
Using testing flags: -DNDEBUG -g2 -O3
g++ -DNDEBUG -g2 -O3 -Wall -fPIC -pthread -pipe -c cryptlib.cpp
g++ -DNDEBUG -g2 -O3 -Wall -fPIC -pthread -pipe -c cpu.cpp
g++ -DNDEBUG -g2 -O3 -Wall -fPIC -pthread -pipe -c integer.cpp
g++ -DNDEBUG -g2 -O3 -Wall -fPIC -pthread -pipe -c 3way.cpp
In file included from cpu.cpp:13:
misc.h:126:19: warning: ‘T {anonymous}::NumericLimitsMax() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMax()
                   ^~~~~~~~~~~~~~~~
misc.h:121:19: warning: ‘T {anonymous}::NumericLimitsMin() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMin()
                   ^~~~~~~~~~~~~~~~
In file included from seckey.h:11,
                 from 3way.h:10,
                 from 3way.cpp:5:
misc.h:126:19: warning: ‘T {anonymous}::NumericLimitsMax() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMax()
                   ^~~~~~~~~~~~~~~~
misc.h:121:19: warning: ‘T {anonymous}::NumericLimitsMin() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMin()
                   ^~~~~~~~~~~~~~~~
g++ -DNDEBUG -g2 -O3 -Wall -fPIC -pthread -pipe -c adler32.cpp
In file included from cryptlib.cpp:19:
misc.h:126:19: warning: ‘T {anonymous}::NumericLimitsMax() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMax()
                   ^~~~~~~~~~~~~~~~
misc.h:121:19: warning: ‘T {anonymous}::NumericLimitsMin() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMin()
                   ^~~~~~~~~~~~~~~~
In file included from secblock.h:11,
                 from integer.h:20,
                 from integer.cpp:54:
misc.h:126:19: warning: ‘T {anonymous}::NumericLimitsMax() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMax()
                   ^~~~~~~~~~~~~~~~
misc.h:121:19: warning: ‘T {anonymous}::NumericLimitsMin() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMin()
                   ^~~~~~~~~~~~~~~~
g++ -DNDEBUG -g2 -O3 -Wall -fPIC -pthread -pipe -c algebra.cpp
g++ -DNDEBUG -g2 -O3 -Wall -fPIC -pthread -pipe -c algparam.cpp
In file included from secblock.h:11,
                 from integer.h:20,
                 from algebra.h:10,
                 from algebra.cpp:8:
misc.h:126:19: warning: ‘T {anonymous}::NumericLimitsMax() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMax()
                   ^~~~~~~~~~~~~~~~
misc.h:121:19: warning: ‘T {anonymous}::NumericLimitsMin() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMin()
                   ^~~~~~~~~~~~~~~~
g++ -DNDEBUG -g2 -O3 -Wall -fPIC -pthread -pipe -c arc4.cpp
In file included from secblock.h:11,
                 from algparam.h:13,
                 from algparam.cpp:7:
misc.h:126:19: warning: ‘T {anonymous}::NumericLimitsMax() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMax()
                   ^~~~~~~~~~~~~~~~
misc.h:121:19: warning: ‘T {anonymous}::NumericLimitsMin() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMin()
                   ^~~~~~~~~~~~~~~~
In file included from seckey.h:11,
                 from strciphr.h:39,
                 from arc4.h:11,
                 from arc4.cpp:11:
misc.h:126:19: warning: ‘T {anonymous}::NumericLimitsMax() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMax()
                   ^~~~~~~~~~~~~~~~
misc.h:121:19: warning: ‘T {anonymous}::NumericLimitsMin() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMin()
                   ^~~~~~~~~~~~~~~~
g++ -DNDEBUG -g2 -O3 -Wall -fPIC -pthread -pipe -c aria.cpp
g++ -DNDEBUG -g2 -O3 -Wall -fPIC -pthread -pipe -mssse3 -c aria_simd.cpp
g++ -DNDEBUG -g2 -O3 -Wall -fPIC -pthread -pipe -c ariatab.cpp
g++ -DNDEBUG -g2 -O3 -Wall -fPIC -pthread -pipe -c asn.cpp
In file included from seckey.h:11,
                 from aria.h:17,
                 from aria.cpp:6:
misc.h:126:19: warning: ‘T {anonymous}::NumericLimitsMax() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMax()
                   ^~~~~~~~~~~~~~~~
misc.h:121:19: warning: ‘T {anonymous}::NumericLimitsMin() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMin()
                   ^~~~~~~~~~~~~~~~
In file included from aria_simd.cpp:11:
misc.h:126:19: warning: ‘T {anonymous}::NumericLimitsMax() [with T = __int128 unsigned]’ defined but not used [-Wunused-function]
 CryptoPP::word128 NumericLimitsMax()
                   ^~~~~~~~~~~~~~~~

@noloader noloader changed the title Including cryptopp headers disables warnings Including Crypto++ headers disables warnings Jan 31, 2019
noloader added a commit that referenced this issue Jan 31, 2019
This was added to misc.h due to the noise created by NumericLimitsMin and NumericLimitsMax. It should make it easier to remove -Wno-unused-function from config.h.
@noloader
Copy link
Collaborator

noloader commented Jan 31, 2019

Commit b29faeab58e7 should help you remove -Wunused-function from config.h. But I don't want to go too far down this rabbit hole.

@espindola
Copy link
Author

Can't the declaration be marked with attirbute((unused)) instead?

@noloader
Copy link
Collaborator

noloader commented Feb 1, 2019

I'm closing this out. This is about as far as I want to go.

I suggest a GCC bug report that asks GCC to stop flagging C++ functions in headers as unused. They are expected.

@noloader noloader closed this as completed Feb 1, 2019
@penberg
Copy link

penberg commented Feb 1, 2019

What GCC version are you using? I don't see those warnings for NumericLimitsMax and others so perhaps the bug is already fixed?

$ g++ --version
g++ (GCC) 8.2.1 20181105 (Red Hat 8.2.1-5)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/config.h b/config.h
index eccba009..2a058ddf 100644
--- a/config.h
+++ b/config.h
@@ -424,7 +424,6 @@ NAMESPACE_END
 // [GCC Bug 53431] "C++ preprocessor ignores #pragma GCC diagnostic". Clang honors it.
 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
 # pragma GCC diagnostic ignored "-Wunknown-pragmas"
-# pragma GCC diagnostic ignored "-Wunused-function"
 #endif

 // You may need to force include a C++ header on Android when using STLPort to ensure
diff --git a/misc.h b/misc.h
index 67e399d4..6b6dd73c 100644
--- a/misc.h
+++ b/misc.h
@@ -23,7 +23,6 @@
 # pragma GCC diagnostic push
 # pragma GCC diagnostic ignored "-Wconversion"
 # pragma GCC diagnostic ignored "-Wsign-conversion"
-# pragma GCC diagnostic ignored "-Wunused-function"
 #endif

 #include "cryptlib.h"
$ CXXFLAGS="-DNDEBUG -g2 -O3 -Wall" make -j 4
crc_simd.cpp:46:17: warning: ‘void CryptoPP::SigIllHandler(int)’ defined but not used [-Wunused-function]
     static void SigIllHandler(int)
                 ^~~~~~~~~~~~~
gcm_simd.cpp:79:17: warning: ‘void CryptoPP::SigIllHandler(int)’ defined but not used [-Wunused-function]
     static void SigIllHandler(int)
                 ^~~~~~~~~~~~~
neon_simd.cpp:43:14: warning: ‘void CryptoPP::SigIllHandler(int)’ defined but not used [-Wunused-function]
  static void SigIllHandler(int)
              ^~~~~~~~~~~~~
ppc_power7.cpp:33:17: warning: ‘void CryptoPP::SigIllHandler(int)’ defined but not used [-Wunused-function]
     static void SigIllHandler(int)
                 ^~~~~~~~~~~~~
ppc_power8.cpp:33:17: warning: ‘void CryptoPP::SigIllHandler(int)’ defined but not used [-Wunused-function]
     static void SigIllHandler(int)
                 ^~~~~~~~~~~~~
ppc_power9.cpp:33:17: warning: ‘void CryptoPP::SigIllHandler(int)’ defined but not used [-Wunused-function]
     static void SigIllHandler(int)
                 ^~~~~~~~~~~~~
ppc_simd.cpp:36:17: warning: ‘void CryptoPP::SigIllHandler(int)’ defined but not used [-Wunused-function]
     static void SigIllHandler(int)
                 ^~~~~~~~~~~~~
rijndael_simd.cpp:77:17: warning: ‘void CryptoPP::SigIllHandler(int)’ defined but not used [-Wunused-function]
     static void SigIllHandler(int)
                 ^~~~~~~~~~~~~
sha_simd.cpp:70:17: warning: ‘void CryptoPP::SigIllHandler(int)’ defined but not used [-Wunused-function]
     static void SigIllHandler(int)
                 ^~~~~~~~~~~~~
simon128_simd.cpp:367:9: warning: ‘__m128i {anonymous}::RotateRight64(const __m128i&) [with unsigned int R = 8]’ defined but not used [-Wunused-function]
 __m128i RotateRight64<8>(const __m128i& val)
         ^~~~~~~~~~~~~~~~
simon64_simd.cpp:345:9: warning: ‘__m128i {anonymous}::RotateRight32(const __m128i&) [with unsigned int R = 8]’ defined but not used [-Wunused-function]
 __m128i RotateRight32<8>(const __m128i& val)
         ^~~~~~~~~~~~~~~~
sse_simd.cpp:45:17: warning: ‘void CryptoPP::SigIllHandlerSSE2(int)’ defined but not used [-Wunused-function]
     static void SigIllHandlerSSE2(int)
                 ^~~~~~~~~~~~~~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants