Skip to content

Commit

Permalink
Remove compiler warnings (incl from third party headers) (nanocurrenc…
Browse files Browse the repository at this point in the history
…y#2072)

* Remove compiler warnings

* Fix new warnings in test

* Remove new msvc warnings
  • Loading branch information
wezrule authored Jul 12, 2019
1 parent 7890e4e commit f8158fc
Show file tree
Hide file tree
Showing 69 changed files with 179 additions and 502 deletions.
2 changes: 1 addition & 1 deletion .clang-format.base
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ IncludeCategories:
- Regex: '<boost/.*>'
Priority: 4
# Headers in other third party libraries
- Regex: '<(gtest|crypto)/([A-Za-z0-9.\/-_])+>'
- Regex: '<(gtest|crypto|miniupnp)/([A-Za-z0-9.\/-_])+>'
Priority: 3
# Headers from nano workspace.
- Regex: '<nano/([A-Za-z0-9.\/-_])+>'
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if (WIN32)
endif()

else ()
add_compile_options(-Werror=switch)
add_compile_options(-Werror)

if ((${USING_TSAN} AND ${USING_ASAN}) OR
(${USING_TSAN} AND ${USING_ASAN_INT}))
Expand Down
1 change: 1 addition & 0 deletions crypto/ed25519-donna/ed25519-donna-portable.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <sys/param.h>
#define DONNA_INLINE inline __attribute__((always_inline))
#define DONNA_NOINLINE __attribute__((noinline))
#undef ALIGN
#define ALIGN(x) __attribute__((aligned(x)))
#define ROTL32(a,b) (((a) << (b)) | ((a) >> (32 - b)))
#define ROTR32(a,b) (((a) >> (b)) | ((a) << (32 - b)))
Expand Down
13 changes: 13 additions & 0 deletions nano/boost/asio.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#ifdef _WIN32
#pragma warning(push)
#pragma warning(disable : 4191)
#pragma warning(disable : 4242)
#endif

#include <boost/asio.hpp>

#ifdef _WIN32
#pragma warning(pop)
#endif
13 changes: 13 additions & 0 deletions nano/boost/beast.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#ifdef _WIN32
#pragma warning(push)
#pragma warning(disable : 4191)
#pragma warning(disable : 4242)
#endif

#include <boost/beast.hpp>

#ifdef _WIN32
#pragma warning(pop)
#endif
22 changes: 22 additions & 0 deletions nano/boost/process.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#ifndef BOOST_PROCESS_SUPPORTED
#error BOOST_PROCESS_SUPPORTED must be set, check configuration
#endif

#if BOOST_PROCESS_SUPPORTED

#ifdef _WIN32
#pragma warning(push)
#pragma warning(disable : 4191)
#pragma warning(disable : 4242)
#pragma warning(disable : 4244)
#endif

#include <boost/process.hpp>

#ifdef _WIN32
#pragma warning(pop)
#endif

#endif
1 change: 1 addition & 0 deletions nano/boost/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
These are files which wrap other boost files and suppress compiler warnings associated with them.
1 change: 0 additions & 1 deletion nano/core_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ add_executable (core_test
difficulty.cpp
entry.cpp
gap_cache.cpp
interface.cpp
ipc.cpp
ledger.cpp
logger.cpp
Expand Down
1 change: 0 additions & 1 deletion nano/core_test/block.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <nano/core_test/testutil.hpp>
#include <nano/lib/interface.h>
#include <nano/node/common.hpp>
#include <nano/node/node.hpp>

Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@ TEST (block_store, peers)
TEST (block_store, endpoint_key_byte_order)
{
boost::asio::ip::address_v6 address (boost::asio::ip::address_v6::from_string ("::ffff:127.0.0.1"));
auto port = 100;
uint16_t port = 100;
nano::endpoint_key endpoint_key (address.to_bytes (), port);

std::vector<uint8_t> bytes;
Expand Down
4 changes: 2 additions & 2 deletions nano/core_test/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ TEST (basic, basic)
TEST (asan, DISABLED_memory)
{
// Ignore warning with gcc/clang compilers
#ifndef MSVC
#ifndef _WIN32
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#endif
uint8_t array[1];
auto value (array[-0x800000]);
(void)value;
#ifndef MSVC
#ifndef _WIN32
#pragma GCC diagnostic pop
#endif
}
162 changes: 0 additions & 162 deletions nano/core_test/interface.cpp

This file was deleted.

4 changes: 2 additions & 2 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ TEST (node, auto_bootstrap)
ASSERT_NO_ERROR (system.poll ());
};
system.deadline_set (5s);
while (node1->stats.count (nano::stat::type::observer, nano::stat::detail::observer_confirmation_active_quorum, nano::stat::dir::out) < 0 || node1->stats.count (nano::stat::type::observer, nano::stat::detail::observer_confirmation_active_conf_height, nano::stat::dir::out) < 0)
while (node1->stats.count (nano::stat::type::observer, nano::stat::detail::observer_confirmation_active_quorum, nano::stat::dir::out) == 0 || node1->stats.count (nano::stat::type::observer, nano::stat::detail::observer_confirmation_active_conf_height, nano::stat::dir::out) == 0)
{
ASSERT_NO_ERROR (system.poll ());
}
Expand Down Expand Up @@ -1635,7 +1635,7 @@ TEST (node, broadcast_elected)
ASSERT_NO_ERROR (ec);
}
system.deadline_set (5s);
while (node1->stats.count (nano::stat::type::observer, nano::stat::detail::observer_confirmation_inactive, nano::stat::dir::out) < 0)
while (node1->stats.count (nano::stat::type::observer, nano::stat::detail::observer_confirmation_inactive, nano::stat::dir::out) == 0)
{
ASSERT_NO_ERROR (system.poll ());
}
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/peer_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ TEST (channels, fill_random_clear)
TEST (channels, fill_random_full)
{
nano::system system (24000, 1);
for (auto i (0); i < 100; ++i)
for (uint16_t i (0u); i < 100u; ++i)
{
system.nodes[0]->network.udp_channels.insert (nano::endpoint (boost::asio::ip::address_v6::loopback (), i), 0);
}
Expand Down
26 changes: 24 additions & 2 deletions nano/core_test/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ TEST (socket, concurrent_writes)
std::function<void(std::shared_ptr<nano::socket>)> reader = [&read_count_completion, &total_message_count, &reader](std::shared_ptr<nano::socket> socket_a) {
auto buff (std::make_shared<std::vector<uint8_t>> ());
buff->resize (1);
#ifndef _WIN32
#pragma GCC diagnostic push
#if defined(__has_warning)
#if __has_warning("-Wunused-lambda-capture")
/** total_message_count is constexpr and a capture isn't needed. However, removing it fails to compile on VS2017 due to a known compiler bug. */
#pragma GCC diagnostic ignored "-Wunused-lambda-capture"
#endif
#endif
#endif
socket_a->async_read (buff, 1, [&read_count_completion, &reader, &total_message_count, socket_a, buff](boost::system::error_code const & ec, size_t size_a) {
if (!ec)
{
Expand All @@ -40,6 +49,9 @@ TEST (socket, concurrent_writes)
std::cerr << "async_read: " << ec.message () << std::endl;
}
});
#ifndef _WIN32
#pragma GCC diagnostic pop
#endif
};

boost::asio::ip::tcp::endpoint endpoint (boost::asio::ip::address_v4::any (), 25000);
Expand Down Expand Up @@ -90,8 +102,15 @@ TEST (socket, concurrent_writes)
std::vector<std::thread> client_threads;
for (int i = 0; i < client_count; i++)
{
// Note: this gives a warning on most compilers because message_count is constexpr and a
// capture isn't needed. However, removing it fails to compile on VS2017 due to a known compiler bug.
#ifndef _WIN32
#pragma GCC diagnostic push
#if defined(__has_warning)
#if __has_warning("-Wunused-lambda-capture")
/** total_message_count is constexpr and a capture isn't needed. However, removing it fails to compile on VS2017 due to a known compiler bug. */
#pragma GCC diagnostic ignored "-Wunused-lambda-capture"
#endif
#endif
#endif
client_threads.emplace_back ([&client, &message_count]() {
for (int i = 0; i < message_count; i++)
{
Expand All @@ -100,6 +119,9 @@ TEST (socket, concurrent_writes)
client->async_write (buff);
}
});
#ifndef _WIN32
#pragma GCC diagnostic pop
#endif
}

ASSERT_FALSE (read_count_completion.await_count_for (10s));
Expand Down
Loading

0 comments on commit f8158fc

Please sign in to comment.