From ed23fd581113d0964f04aa45e9aedf6511b2e679 Mon Sep 17 00:00:00 2001 From: Andrew Whatson Date: Thu, 13 Oct 2016 12:32:01 +1000 Subject: [PATCH] Fix unused parameter warnings and missing includes: fix #127 * Added beast::detail::ignore_unused based on boost::ignore_unused * Added -Wextra compilation flag when building with gcc * Fixed all unused parameter warnings with ignore_unused * Fixed all missing includes when building each .hpp separately --- CMakeLists.txt | 2 +- examples/http_sync_server.hpp | 3 +++ extras/beast/test/string_stream.hpp | 1 + include/beast/core/detail/type_traits.hpp | 13 +++++++++++++ include/beast/core/impl/basic_streambuf.ipp | 2 ++ include/beast/http/basic_dynabuf_body.hpp | 2 ++ include/beast/http/empty_body.hpp | 3 +++ include/beast/http/impl/message.ipp | 4 ++++ include/beast/http/parser_v1.hpp | 7 ++++--- include/beast/http/string_body.hpp | 2 ++ include/beast/websocket/detail/hybi13.hpp | 1 + include/beast/websocket/impl/accept_op.ipp | 4 +++- test/http/message_fuzz.hpp | 1 + test/http/nodejs_parser.hpp | 3 ++- test/http/write.cpp | 3 ++- test/websocket/stream.cpp | 2 +- test/websocket/websocket_sync_echo_server.hpp | 3 ++- 17 files changed, 47 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b390bb0..27ed6c1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ else() find_package(Threads) set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wpedantic") + "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wpedantic") endif() if (APPLE AND NOT DEFINED ENV{OPENSSL_ROOT_DIR}) diff --git a/examples/http_sync_server.hpp b/examples/http_sync_server.hpp index 271fe21b..8dfe45d4 100644 --- a/examples/http_sync_server.hpp +++ b/examples/http_sync_server.hpp @@ -11,6 +11,8 @@ #include "file_body.hpp" #include "mime_type.hpp" +#include +#include #include #include #include @@ -19,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/extras/beast/test/string_stream.hpp b/extras/beast/test/string_stream.hpp index fcf77aae..a8bd0b7e 100644 --- a/extras/beast/test/string_stream.hpp +++ b/extras/beast/test/string_stream.hpp @@ -8,6 +8,7 @@ #ifndef BEAST_TEST_STRING_STREAM_HPP #define BEAST_TEST_STRING_STREAM_HPP +#include #include #include #include diff --git a/include/beast/core/detail/type_traits.hpp b/include/beast/core/detail/type_traits.hpp index 3944e514..93b1ad05 100644 --- a/include/beast/core/detail/type_traits.hpp +++ b/include/beast/core/detail/type_traits.hpp @@ -20,6 +20,19 @@ struct make_void template using void_t = typename make_void::type; +template +inline +void +ignore_unused(Ts const& ...) +{ +} + +template +inline +void +ignore_unused() +{} + } // detail } // beast diff --git a/include/beast/core/impl/basic_streambuf.ipp b/include/beast/core/impl/basic_streambuf.ipp index fb091496..f59d00df 100644 --- a/include/beast/core/impl/basic_streambuf.ipp +++ b/include/beast/core/impl/basic_streambuf.ipp @@ -8,6 +8,7 @@ #ifndef BEAST_IMPL_BASIC_STREAMBUF_IPP #define BEAST_IMPL_BASIC_STREAMBUF_IPP +#include #include #include #include @@ -786,6 +787,7 @@ void basic_streambuf:: copy_assign(basic_streambuf const& other, std::false_type) { + beast::detail::ignore_unused(other); } template diff --git a/include/beast/http/basic_dynabuf_body.hpp b/include/beast/http/basic_dynabuf_body.hpp index f39defc7..4d331380 100644 --- a/include/beast/http/basic_dynabuf_body.hpp +++ b/include/beast/http/basic_dynabuf_body.hpp @@ -9,6 +9,7 @@ #define BEAST_HTTP_BASIC_DYNABUF_BODY_HPP #include +#include #include namespace beast { @@ -73,6 +74,7 @@ private: void init(error_code& ec) noexcept { + beast::detail::ignore_unused(ec); } std::uint64_t diff --git a/include/beast/http/empty_body.hpp b/include/beast/http/empty_body.hpp index 1c1d45a7..b76e02d7 100644 --- a/include/beast/http/empty_body.hpp +++ b/include/beast/http/empty_body.hpp @@ -9,6 +9,7 @@ #define BEAST_HTTP_EMPTY_BODY_HPP #include +#include #include #include #include @@ -39,11 +40,13 @@ private: explicit writer(message const& m) noexcept { + beast::detail::ignore_unused(m); } void init(error_code& ec) noexcept { + beast::detail::ignore_unused(ec); } std::uint64_t diff --git a/include/beast/http/impl/message.ipp b/include/beast/http/impl/message.ipp index fa898cd5..6d853587 100644 --- a/include/beast/http/impl/message.ipp +++ b/include/beast/http/impl/message.ipp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -61,6 +62,7 @@ void prepare_options(prepare_info& pi, message& msg) { + beast::detail::ignore_unused(pi, msg); } template @@ -69,6 +71,7 @@ prepare_option(prepare_info& pi, message& msg, connection value) { + beast::detail::ignore_unused(msg); pi.connection_value = value; } @@ -106,6 +109,7 @@ prepare_content_length(prepare_info& pi, message const& msg, std::false_type) { + beast::detail::ignore_unused(msg); pi.content_length = boost::none; } diff --git a/include/beast/http/parser_v1.hpp b/include/beast/http/parser_v1.hpp index 703326b2..a690919e 100644 --- a/include/beast/http/parser_v1.hpp +++ b/include/beast/http/parser_v1.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -231,13 +232,13 @@ private: m_.reason = std::move(this->reason_); } - void on_request(error_code& ec) + void on_request(error_code&) { on_request_or_response( std::integral_constant{}); } - void on_response(error_code& ec) + void on_response(error_code&) { on_request_or_response( std::integral_constant{}); @@ -256,7 +257,7 @@ private: } void - on_headers(std::uint64_t, error_code& ec) + on_headers(std::uint64_t, error_code&) { flush(); m_.version = 10 * this->http_major() + this->http_minor(); diff --git a/include/beast/http/string_body.hpp b/include/beast/http/string_body.hpp index 25790487..f5445e2f 100644 --- a/include/beast/http/string_body.hpp +++ b/include/beast/http/string_body.hpp @@ -9,6 +9,7 @@ #define BEAST_HTTP_STRING_BODY_HPP #include +#include #include #include #include @@ -73,6 +74,7 @@ private: void init(error_code& ec) noexcept { + beast::detail::ignore_unused(ec); } std::uint64_t diff --git a/include/beast/websocket/detail/hybi13.hpp b/include/beast/websocket/detail/hybi13.hpp index 72999f68..b7ecb66a 100644 --- a/include/beast/websocket/detail/hybi13.hpp +++ b/include/beast/websocket/detail/hybi13.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/include/beast/websocket/impl/accept_op.ipp b/include/beast/websocket/impl/accept_op.ipp index 43ad95a0..82524fff 100644 --- a/include/beast/websocket/impl/accept_op.ipp +++ b/include/beast/websocket/impl/accept_op.ipp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -112,11 +113,12 @@ public: template template -void +void stream::accept_op:: operator()(error_code const& ec, std::size_t bytes_transferred, bool again) { + beast::detail::ignore_unused(bytes_transferred); auto& d = *d_; d.cont = d.cont || again; while(! ec && d.state != 99) diff --git a/test/http/message_fuzz.hpp b/test/http/message_fuzz.hpp index e736c960..6f38b750 100644 --- a/test/http/message_fuzz.hpp +++ b/test/http/message_fuzz.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include diff --git a/test/http/nodejs_parser.hpp b/test/http/nodejs_parser.hpp index 0adb8c12..76110050 100644 --- a/test/http/nodejs_parser.hpp +++ b/test/http/nodejs_parser.hpp @@ -795,7 +795,7 @@ private: bool on_request(unsigned method, std::string const& url, - int major, int minor, bool keep_alive, bool upgrade, + int major, int minor, bool /*keep_alive*/, bool /*upgrade*/, std::true_type) { m_.method = detail::method_to_string(method); @@ -826,6 +826,7 @@ private: int major, int minor, bool keep_alive, bool upgrade, std::true_type) { + beast::detail::ignore_unused(keep_alive, upgrade); m_.status = status; m_.reason = reason; m_.version = major * 10 + minor; diff --git a/test/http/write.cpp b/test/http/write.cpp index 5ecd9c37..dcb5f3c4 100644 --- a/test/http/write.cpp +++ b/test/http/write.cpp @@ -64,7 +64,7 @@ public: template std::size_t write_some( - ConstBufferSequence const& buffers, error_code& ec) + ConstBufferSequence const& buffers, error_code&) { auto const n = buffer_size(buffers); using boost::asio::buffer_size; @@ -112,6 +112,7 @@ public: void init(error_code& ec) noexcept { + beast::detail::ignore_unused(ec); } template diff --git a/test/websocket/stream.cpp b/test/websocket/stream.cpp index b03fa40c..f35e19f4 100644 --- a/test/websocket/stream.cpp +++ b/test/websocket/stream.cpp @@ -490,7 +490,7 @@ public: } } - void testClose(endpoint_type const& ep, yield_context do_yield) + void testClose(endpoint_type const& ep, yield_context) { { // payload length 1 diff --git a/test/websocket/websocket_sync_echo_server.hpp b/test/websocket/websocket_sync_echo_server.hpp index a09e4750..ca7a8486 100644 --- a/test/websocket/websocket_sync_echo_server.hpp +++ b/test/websocket/websocket_sync_echo_server.hpp @@ -8,6 +8,7 @@ #ifndef BEAST_WEBSOCKET_SYNC_ECHO_PEER_H_INCLUDED #define BEAST_WEBSOCKET_SYNC_ECHO_PEER_H_INCLUDED +#include #include #include #include @@ -36,7 +37,7 @@ private: std::thread thread_; public: - sync_echo_server(bool server, endpoint_type ep) + sync_echo_server(bool /*server*/, endpoint_type ep) : sock_(ios_) , acceptor_(ios_) {