Skip to content

Commit

Permalink
build: Enable some commonly enabled compiler diagnostics
Browse files Browse the repository at this point in the history
Summary:
> as discussed in [[ bitcoin/bitcoin#17344 | #17344]]
>
> There is a large overlap between this list and Jason Turner's list of recommended compiler diagnostics in the Collaborative Collection of C++ Best Practices (cppbestpractices) project. There is also an overlap with the recommendations given in the C++ Core Guidelines (with editors Bjarne Stroustrup and Herb Sutter).

This is a backport of [[bitcoin/bitcoin#19015 | core#19015]]

Disable `-Wduplicated-branches` for secp256k1, because of some exotic intentional use of ternary operator duplicated branches in test_inverse_scalar.

Test Plan:
```
cmake .. -GNinja -DCMAKE_CXX_FLAGS=-Werror -DCMAKE_C_FLAGS=-Werror
ninja && ninja check && ninja check-secp256k1
rm -Rf *
cmake .. -GNinja  -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS=-Werror  -DCMAKE_C_FLAGS=-Werror
ninja && ninja check && ninja check-secp256k1
```

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10113
  • Loading branch information
PiRK committed Sep 15, 2021
1 parent 5805c64 commit 5c2868f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -228,10 +228,14 @@ add_compiler_flags(
-Wunreachable-code-loop-increment
-Wsign-compare
-Wconditional-uninitialized
-Wduplicated-branches
-Wduplicated-cond
-Wlogical-op
)
add_compiler_flag_group(-Wformat -Wformat-security)
add_cxx_compiler_flags(
-Wredundant-move
-Woverloaded-virtual
)

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Expand Down
1 change: 1 addition & 0 deletions src/secp256k1/CMakeLists.txt
Expand Up @@ -52,6 +52,7 @@ add_c_compiler_flags(
-Wnested-externs
-Wstrict-prototypes
-Wno-long-long
-Wno-duplicated-branches
)

# Default visibility is hidden on all targets.
Expand Down
3 changes: 3 additions & 0 deletions src/test/rpc_server_tests.cpp
Expand Up @@ -24,6 +24,9 @@ class ArgsTestRPCCommand : public RPCCommandWithArgsContext {
explicit ArgsTestRPCCommand(const std::string &nameIn)
: RPCCommandWithArgsContext(nameIn) {}

// Suppress a [-Werror=overloaded-virtual] warning
using RPCCommandWithArgsContext::Execute;

UniValue Execute(const UniValue &args) const override {
BOOST_CHECK_EQUAL(args["arg1"].get_str(), "value1");
return UniValue("testing1");
Expand Down

0 comments on commit 5c2868f

Please sign in to comment.