I tried gcc and clang, but those failures won’t show for me. See #18637 (comment)
While I like the warning and error, if developers can’t see them on their boxes, it makes it tedious to fix those issues up.
I tried gcc and clang, but those failures won’t show for me. See #18637 (comment)
While I like the warning and error, if developers can’t see them on their boxes, it makes it tedious to fix those issues up.
 0#include <cstddef>
 1
 2int main(void)
 3{
 4    int x = -2;
 5    size_t y = 3;
 6    if (x == y*y) {
 7        return 1;
 8    }
 9    return 0;
10}
gives me errors for both gcc (v9.3) and clang (v9.0):
0$ g++ -Wall -W -Werror -o testsign test.cc
1test.cc: In function ‘int main()’:
2test.cc:7:11: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare]
3    7 |     if (x == y*y) {
4      |         ~~^~~~~~
5cc1plus: all warnings being treated as errors
0$ clang++ -Wall -W -Werror -o testsign test.cc
1test.cc:7:11: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
2    if (x == y*y) {
3        ~ ^  ~~~
41 error generated.
If I say if (x*x == y*y), g++ stops complaining though.
Steps to reproduce on commit 5f96bce9b7f38c687817d58e8b54a5b7ebfe91b3
 0Options used to compile and link:
 1  multiprocess  = no
 2  with wallet   = yes
 3  with gui / qt = yes
 4    with qr     = yes
 5  with zmq      = yes
 6  with test     = yes
 7    with fuzz   = no
 8  with bench    = yes
 9  with upnp     = no
10  use asm       = yes
11  sanitizers    = 
12  debug enabled = no
13  gprof enabled = no
14  werror        = no
15
16  target os     = linux
17  build os      = linux-gnu
18
19  CC            = /usr/bin/ccache clang
20  CFLAGS        = -g -O2
21  CPPFLAGS      =   -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2  -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS
22  CXX           = /usr/bin/ccache clang++ -std=c++17
23  CXXFLAGS      =   -Wstack-protector -fstack-protector-all  -Wall -Wextra -Wgnu -Wformat -Wvla -Wshadow-field -Wswitch -Wformat-security -Wthread-safety -Wrange-loop-analysis -Wredundant-decls -Wunused-variable -Wdate-time -Wconditional-uninitialized -Wsign-compare -Wunreachable-code-loop-increment  -Wno-unused-parameter -Wno-self-assign -Wno-unused-local-typedef -Wno-deprecated-register -Wno-implicit-fallthrough -Wno-deprecated-copy   -g -O2
24  LDFLAGS       = -pthread  -Wl,-z,relro -Wl,-z,now -pie  
25  ARFLAGS       = cr
 0Options used to compile and link:
 1  multiprocess  = no
 2  with wallet   = yes
 3  with gui / qt = yes
 4    with qr     = yes
 5  with zmq      = yes
 6  with test     = yes
 7    with fuzz   = no
 8  with bench    = yes
 9  with upnp     = no
10  use asm       = yes
11  sanitizers    = 
12  debug enabled = no
13  gprof enabled = no
14  werror        = no
15
16  target os     = linux
17  build os      = linux-gnu
18
19  CC            = /usr/bin/ccache gcc
20  CFLAGS        = -g -O2
21  CPPFLAGS      =   -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2  -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS
22  CXX           = /usr/bin/ccache g++ -std=c++11
23  CXXFLAGS      =   -fstack-reuse=none -Wstack-protector -fstack-protector-all  -Wall -Wextra -Wformat -Wvla -Wswitch -Wredundant-decls -Wunused-variable -Wdate-time -Wsign-compare -Wsuggest-override  -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-deprecated-copy   -g -O2 -fno-extended-identifiers
24  LDFLAGS       = -pthread  -Wl,-z,relro -Wl,-z,now -pie  
25  ARFLAGS       = cr
If I checkout 5f96bce9b7f38c687817d58e8b54a5b7ebfe91b3 and apply
 0$ git diff
 1diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
 2index 0f7c3e5b39..54a2b53182 100644
 3--- a/src/wallet/test/wallet_tests.cpp
 4+++ b/src/wallet/test/wallet_tests.cpp
 5@@ -812,6 +812,11 @@ BOOST_FIXTURE_TEST_CASE(ZapSelectTx, TestChain100Setup)
 6 
 7         LOCK(wallet->cs_wallet);
 8         BOOST_CHECK(wallet->HasWalletSpend(prev_hash));
 9+        int x = 1;
10+        if (wallet->mapWallet.count(block_hash) == 1) (void)0;
11+        if (wallet->mapWallet.count(block_hash) == (int)1) (void)0;
12+        if (wallet->mapWallet.count(block_hash) == x) (void)0;
13+        if (wallet->mapWallet.count(block_hash) == -1) (void)0;
14         BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_hash), 1);
15 
16         std::vector<uint256> vHashIn{ block_hash }, vHashOut;
Then ./configure CC=clang CXX=clang++ --with-incompatible-bdb --enable-zmq --without-miniupnpc --enable-c++17 (clang 9.0.1) I get the following errors:
0wallet/test/wallet_tests.cpp:818:49: warning: comparison of integers of different signs: 'std::map<uint256, CWalletTx, std::less<uint256>, std::allocator<std::pair<const uint256, CWalletTx> > >::size_type' (aka 'unsigned long') and 'int' [-Wsign-compare]
1        if (wallet->mapWallet.count(block_hash) == x) (void)0;
2            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~
3wallet/test/wallet_tests.cpp:819:49: warning: comparison of integers of different signs: 'std::map<uint256, CWalletTx, std::less<uint256>, std::allocator<std::pair<const uint256, CWalletTx> > >::size_type' (aka 'unsigned long') and 'int' [-Wsign-compare]
4        if (wallet->mapWallet.count(block_hash) == -1) (void)0;
same errors with gcc (9.3.0), give or take some wording. The two travis reports reportedly have clang version 7.0.0, and Apple clang 11.0.0, both of which I think are Xcode versions rather than llvm versions. Wikipedia claims xcode clang 11.0.0 corresponds to llvm clang 8.0.0, but trying clang 8 and clang 7 in Debian, and clang 6 in bionic gives me the same collection of errors as above, so I think this must be some Xcode specific thing, where other compilers are able to figure out the value is a constant that’s always in range, and just emit correct code, rather than a warning?
I’m currently running Mac OS 10.15.7 (19H1217)
0$ /usr/local/bin/ccache gcc --version
1Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1
2Apple clang version 12.0.0 (clang-1200.0.32.29)
3Target: x86_64-apple-darwin19.6.0
4Thread model: posix
5InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 0Options used to compile and link:
 1  external signer = no
 2  multiprocess    = no
 3  with libs       = yes
 4  with wallet     = yes
 5    with sqlite   = yes
 6    with bdb      = yes
 7  with gui / qt   = yes
 8    with qr       = yes
 9  with zmq        = no
10  with test       = yes
11  with bench      = yes
12  with upnp       = yes
13  with natpmp     = no
14  use asm         = yes
15  ebpf tracing    = yes
16  sanitizers      = 
17  debug enabled   = no
18  gprof enabled   = no
19  werror          = no
20
21  target os       = darwin
22  build os        = darwin19.6.0
23
24  CC              = /usr/local/bin/ccache gcc
25  CFLAGS          = -pthread -g -O2
26  CPPFLAGS        =  -fmacro-prefix-map=$(abs_srcdir)=.  -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2  -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS -DMAC_OSX -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -DPROVIDE_FUZZ_MAIN_FUNCTION
27  CXX             = /usr/local/bin/ccache g++ -std=c++17
28  CXXFLAGS        =  -fdebug-prefix-map=$(abs_srcdir)=.  -Wstack-protector -fstack-protector-all -fcf-protection=full  -Wall -Wextra -Wgnu -Wformat -Wformat-security -Wvla -Wshadow-field -Wswitch -Wthread-safety -Wrange-loop-analysis -Wredundant-decls -Wunused-variable -Wunused-member-function -Wdate-time -Wconditional-uninitialized -Wsign-compare -Woverloaded-virtual -Wunreachable-code-loop-increment  -Wno-unused-parameter -Wno-self-assign -Wno-unused-local-typedef -Wno-implicit-fallthrough   -g -O2
29  LDFLAGS         = -lpthread  -Wl,-bind_at_load   -Wl,-headerpad_max_install_names -Wl,-dead_strip -Wl,-dead_strip_dylibs
30  ARFLAGS         = cr
The above setting show warnings when building 93e38d5c06d9b32326585121b46bb59041d7cfed.
Another way to reproduce (at least for 32-bit) would be:
( cd depends && make HOST=i686-pc-linux-gnu CC='clang -m32' CXX='clang++ -m32 -Wsign-compare' NO_QT=1 NO_WALLET=1 NO_ZMQ=1 NO_UPNP=1 NO_NATPMP=1 -j $(nproc) ) && ./autogen.sh && CONFIG_SITE="$PWD/depends/i686-pc-linux-gnu/share/config.site" ./configure  && make  -j $(nproc) src/bitcoind
          Labels
          
          
  
    
Questions and Help