From 5bff4ed8ab3aecd608f4401ba8f3a4059098b037 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 22 Nov 2018 20:49:30 -0800 Subject: [PATCH] Tidy up warnings and deprecated usage: fix #1290 * BOOST_ASIO_NO_DEPRECATED=1 is now set * Fix various warnings from the Boost regression test matrix * Fix a bug in advanced servers when checking for a timeout --- CHANGELOG.md | 1 + CMakeLists.txt | 14 ++++++----- Jamfile | 4 ++- .../server-flex/advanced_server_flex.cpp | 2 +- example/advanced/server/advanced_server.cpp | 2 +- .../_experimental/unit_test/recorder.hpp | 3 --- test/beast/core/bind_handler.cpp | 2 +- test/beast/core/buffered_read_stream.cpp | 9 ++++--- test/beast/core/buffers_cat.cpp | 4 +-- test/beast/experimental/CMakeLists.txt | 2 +- test/beast/experimental/icy_stream.cpp | 2 +- test/beast/experimental/timeout_socket.cpp | 4 +-- test/beast/http/read.cpp | 25 +++++++++++++------ test/beast/http/write.cpp | 23 +++++++++++------ test/beast/websocket/accept.cpp | 9 ++++--- test/beast/websocket/close.cpp | 9 ++++--- test/beast/websocket/handshake.cpp | 10 +++++--- test/beast/websocket/ping.cpp | 9 ++++--- test/beast/websocket/read2.cpp | 9 ++++--- test/beast/websocket/write.cpp | 9 ++++--- test/doc/core_snippets.cpp | 8 +++--- test/doc/websocket_snippets.cpp | 1 + .../boost/beast/test/test_allocator.hpp | 2 +- 23 files changed, 103 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d11b62a2..ce678721 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 192: * Use mp11::integer_sequence +* Tidy up warnings and deprecated usage -------------------------------------------------------------------------------- diff --git a/CMakeLists.txt b/CMakeLists.txt index 7dbe7ced..b54bf044 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,9 +18,13 @@ option (Beast_BUILD_TESTS "Build tests" ON) if (MSVC) set (CMAKE_VERBOSE_MAKEFILE FALSE) - add_definitions (-D_WIN32_WINNT=0x0601) - add_definitions (-D_SCL_SECURE_NO_WARNINGS=1) - add_definitions (-D_CRT_SECURE_NO_WARNINGS=1) + add_definitions ( + -D_WIN32_WINNT=0x0601 + -D_SCL_SECURE_NO_WARNINGS=1 + -D_CRT_SECURE_NO_WARNINGS=1 + -D_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING + -D_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING + ) add_compile_options( /bigobj # large object file format @@ -74,9 +78,7 @@ get_filename_component (BOOST_ROOT ../../ ABSOLUTE) # VFALCO I want static but "b2 stage" builds a minimal set which excludes static add_definitions (-DBOOST_ALL_STATIC_LINK=1) -# Some of the tests use deprecated APIs -#add_definitions (-DBOOST_ASIO_NO_DEPRECATED=1) - +add_definitions (-DBOOST_ASIO_NO_DEPRECATED=1) add_definitions (-DBOOST_ASIO_DISABLE_BOOST_ARRAY=1) add_definitions (-DBOOST_ASIO_DISABLE_BOOST_BIND=1) add_definitions (-DBOOST_ASIO_DISABLE_BOOST_DATE_TIME=1) diff --git a/Jamfile b/Jamfile index 7893775c..6ec99363 100644 --- a/Jamfile +++ b/Jamfile @@ -97,15 +97,17 @@ project /boost/beast shared on BOOST_ALL_NO_LIB=1 + BOOST_ASIO_NO_DEPRECATED=1 BOOST_ASIO_DISABLE_BOOST_ARRAY=1 BOOST_ASIO_DISABLE_BOOST_BIND=1 BOOST_ASIO_DISABLE_BOOST_DATE_TIME=1 BOOST_ASIO_DISABLE_BOOST_REGEX=1 - #BOOST_ASIO_NO_DEPRECATED=1 # some tests use deprecated strand BOOST_COROUTINES_NO_DEPRECATION_WARNING=1 msvc:"/bigobj /permissive-" msvc:_SCL_SECURE_NO_WARNINGS=1 msvc:_CRT_SECURE_NO_WARNINGS=1 + msvc:_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING + msvc:_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING msvc,release:"/Ob2 /Oi /Ot" SOLARIS:socket SOLARIS:nsl diff --git a/example/advanced/server-flex/advanced_server_flex.cpp b/example/advanced/server-flex/advanced_server_flex.cpp index 09214158..4c721459 100644 --- a/example/advanced/server-flex/advanced_server_flex.cpp +++ b/example/advanced/server-flex/advanced_server_flex.cpp @@ -809,7 +809,7 @@ public: return fail(ec, "timer"); // Check if this has been upgraded to Websocket - if(timer_.expires_at() == (std::chrono::steady_clock::time_point::min)()) + if(timer_.expiry() == (std::chrono::steady_clock::time_point::min)()) return; // Verify that the timer really expired since the deadline may have moved. diff --git a/example/advanced/server/advanced_server.cpp b/example/advanced/server/advanced_server.cpp index 829b2dc8..14c52e34 100644 --- a/example/advanced/server/advanced_server.cpp +++ b/example/advanced/server/advanced_server.cpp @@ -622,7 +622,7 @@ public: return fail(ec, "timer"); // Check if this has been upgraded to Websocket - if(timer_.expires_at() == (std::chrono::steady_clock::time_point::min)()) + if(timer_.expiry() == (std::chrono::steady_clock::time_point::min)()) return; // Verify that the timer really expired since the deadline may have moved. diff --git a/include/boost/beast/_experimental/unit_test/recorder.hpp b/include/boost/beast/_experimental/unit_test/recorder.hpp index 7bc31df7..a44a9e32 100644 --- a/include/boost/beast/_experimental/unit_test/recorder.hpp +++ b/include/boost/beast/_experimental/unit_test/recorder.hpp @@ -20,15 +20,12 @@ namespace unit_test { /** A test runner that stores the results. */ class recorder : public runner { -private: results m_results; suite_results m_suite; case_results m_case; public: recorder() = default; - recorder(recorder const&) = default; - recorder& operator=(recorder const&) = default; /** Returns a report with the results of all completed suites. */ results const& diff --git a/test/beast/core/bind_handler.cpp b/test/beast/core/bind_handler.cpp index bd8c4e2a..8fe5c088 100644 --- a/test/beast/core/bind_handler.cpp +++ b/test/beast/core/bind_handler.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include diff --git a/test/beast/core/buffered_read_stream.cpp b/test/beast/core/buffered_read_stream.cpp index 6aca2cf0..bb1e7ef4 100644 --- a/test/beast/core/buffered_read_stream.cpp +++ b/test/beast/core/buffered_read_stream.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -224,12 +224,15 @@ public: // breakpoint in asio_handler_invoke to make sure // it is instantiated. boost::asio::io_context ioc; - boost::asio::io_service::strand s{ioc}; + boost::asio::strand< + boost::asio::io_context::executor_type> s( + ioc.get_executor()); test::stream ts{ioc}; buffered_read_stream< test::stream&, multi_buffer> brs(ts); brs.async_read_some(boost::asio::mutable_buffer{}, - s.wrap(copyable_handler{})); + boost::asio::bind_executor( + s, copyable_handler{})); } void run() override diff --git a/test/beast/core/buffers_cat.cpp b/test/beast/core/buffers_cat.cpp index ca2ea93a..3800072c 100644 --- a/test/beast/core/buffers_cat.cpp +++ b/test/beast/core/buffers_cat.cpp @@ -130,8 +130,8 @@ public: decltype(bs)::const_iterator copy; copy = it; BEAST_EXPECT(copy == it); - copy = copy; - BEAST_EXPECT(copy == it); + auto copy2 = copy; + BEAST_EXPECT(copy2 == it); } } diff --git a/test/beast/experimental/CMakeLists.txt b/test/beast/experimental/CMakeLists.txt index 09d1416a..14595e19 100644 --- a/test/beast/experimental/CMakeLists.txt +++ b/test/beast/experimental/CMakeLists.txt @@ -9,7 +9,7 @@ GroupSources (include/boost/beast beast) GroupSources (test/extras/include/boost/beast extras) -GroupSources (test/beast/_experimental "/") +GroupSources (test/beast/experimental "/") add_executable (tests-beast-experimental ${BOOST_BEAST_FILES} diff --git a/test/beast/experimental/icy_stream.cpp b/test/beast/experimental/icy_stream.cpp index 1e7bcd28..28bd1e9d 100644 --- a/test/beast/experimental/icy_stream.cpp +++ b/test/beast/experimental/icy_stream.cpp @@ -88,7 +88,7 @@ public: ba.commit(n); }); ioc.run(); - ioc.reset(); + ioc.restart(); if(ec) break; } diff --git a/test/beast/experimental/timeout_socket.cpp b/test/beast/experimental/timeout_socket.cpp index 36a03d55..c5241c91 100644 --- a/test/beast/experimental/timeout_socket.cpp +++ b/test/beast/experimental/timeout_socket.cpp @@ -98,14 +98,12 @@ public: : public std::enable_shared_from_this { boost::asio::ip::tcp::socket socket_; - std::ostream& log_; public: session( boost::asio::ip::tcp::socket sock, - std::ostream& log) + std::ostream&) : socket_(std::move(sock)) - , log_(log) { } diff --git a/test/beast/http/read.cpp b/test/beast/http/read.cpp index 360c5686..b639c5fa 100644 --- a/test/beast/http/read.cpp +++ b/test/beast/http/read.cpp @@ -19,9 +19,9 @@ #include #include #include -#include #include -#include +#include +#include #include #include @@ -493,32 +493,41 @@ public: void testAsioHandlerInvoke() { + using strand = boost::asio::strand< + boost::asio::io_context::executor_type>; + // make sure things compile, also can set a // breakpoint in asio_handler_invoke to make sure // it is instantiated. { boost::asio::io_context ioc; - boost::asio::io_service::strand s{ioc}; + strand s{ioc.get_executor()}; test::stream ts{ioc}; flat_buffer b; request_parser p; - async_read_some(ts, b, p, s.wrap(copyable_handler{})); + async_read_some(ts, b, p, + boost::asio::bind_executor( + s, copyable_handler{})); } { boost::asio::io_context ioc; - boost::asio::io_service::strand s{ioc}; + strand s{ioc.get_executor()}; test::stream ts{ioc}; flat_buffer b; request_parser p; - async_read(ts, b, p, s.wrap(copyable_handler{})); + async_read(ts, b, p, + boost::asio::bind_executor( + s, copyable_handler{})); } { boost::asio::io_context ioc; - boost::asio::io_service::strand s{ioc}; + strand s{ioc.get_executor()}; test::stream ts{ioc}; flat_buffer b; request m; - async_read(ts, b, m, s.wrap(copyable_handler{})); + async_read(ts, b, m, + boost::asio::bind_executor( + s, copyable_handler{})); } } diff --git a/test/beast/http/write.cpp b/test/beast/http/write.cpp index e90bdd5b..2ec038e0 100644 --- a/test/beast/http/write.cpp +++ b/test/beast/http/write.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -857,34 +857,43 @@ public: void testAsioHandlerInvoke() { + using strand = boost::asio::strand< + boost::asio::io_context::executor_type>; + // make sure things compile, also can set a // breakpoint in asio_handler_invoke to make sure // it is instantiated. { boost::asio::io_context ioc; - boost::asio::io_service::strand s{ioc}; + strand s{ioc.get_executor()}; test::stream ts{ioc}; flat_buffer b; request m; request_serializer sr{m}; - async_write_some(ts, sr, s.wrap(copyable_handler{})); + async_write_some(ts, sr, + boost::asio::bind_executor( + s, copyable_handler{})); } { boost::asio::io_context ioc; - boost::asio::io_service::strand s{ioc}; + strand s{ioc.get_executor()}; test::stream ts{ioc}; flat_buffer b; request m; request_serializer sr{m}; - async_write(ts, sr, s.wrap(copyable_handler{})); + async_write(ts, sr, + boost::asio::bind_executor( + s, copyable_handler{})); } { boost::asio::io_context ioc; - boost::asio::io_service::strand s{ioc}; + strand s{ioc.get_executor()}; test::stream ts{ioc}; flat_buffer b; request m; - async_write(ts, m, s.wrap(copyable_handler{})); + async_write(ts, m, + boost::asio::bind_executor( + s, copyable_handler{})); } } diff --git a/test/beast/websocket/accept.cpp b/test/beast/websocket/accept.cpp index 9f654595..a66f4525 100644 --- a/test/beast/websocket/accept.cpp +++ b/test/beast/websocket/accept.cpp @@ -12,7 +12,7 @@ #include "test.hpp" -#include +#include #include namespace boost { @@ -637,9 +637,12 @@ public: // breakpoint in asio_handler_invoke to make sure // it is instantiated. boost::asio::io_context ioc; - boost::asio::io_service::strand s{ioc}; + boost::asio::strand< + boost::asio::io_context::executor_type> s( + ioc.get_executor()); stream ws{ioc}; - ws.async_accept(s.wrap(copyable_handler{})); + ws.async_accept(boost::asio::bind_executor( + s, copyable_handler{})); } void diff --git a/test/beast/websocket/close.cpp b/test/beast/websocket/close.cpp index 1a8625dc..5b25321b 100644 --- a/test/beast/websocket/close.cpp +++ b/test/beast/websocket/close.cpp @@ -12,7 +12,7 @@ #include "test.hpp" -#include +#include #include namespace boost { @@ -649,9 +649,12 @@ public: // breakpoint in asio_handler_invoke to make sure // it is instantiated. boost::asio::io_context ioc; - boost::asio::io_service::strand s{ioc}; + boost::asio::strand< + boost::asio::io_context::executor_type> s( + ioc.get_executor()); stream ws{ioc}; - ws.async_close({}, s.wrap(copyable_handler{})); + ws.async_close({}, boost::asio::bind_executor( + s, copyable_handler{})); } void diff --git a/test/beast/websocket/handshake.cpp b/test/beast/websocket/handshake.cpp index 61a861f7..69397922 100644 --- a/test/beast/websocket/handshake.cpp +++ b/test/beast/websocket/handshake.cpp @@ -12,7 +12,7 @@ #include "test.hpp" -#include +#include #include namespace boost { @@ -511,9 +511,13 @@ public: // breakpoint in asio_handler_invoke to make sure // it is instantiated. boost::asio::io_context ioc; - boost::asio::io_service::strand s{ioc}; + boost::asio::strand< + boost::asio::io_context::executor_type> s( + ioc.get_executor()); stream ws{ioc}; - ws.async_handshake("localhost", "/", s.wrap(copyable_handler{})); + ws.async_handshake("localhost", "/", + boost::asio::bind_executor( + s, copyable_handler{})); } void diff --git a/test/beast/websocket/ping.cpp b/test/beast/websocket/ping.cpp index 9bca3cdc..49be4808 100644 --- a/test/beast/websocket/ping.cpp +++ b/test/beast/websocket/ping.cpp @@ -12,7 +12,7 @@ #include "test.hpp" -#include +#include #include namespace boost { @@ -462,9 +462,12 @@ public: // breakpoint in asio_handler_invoke to make sure // it is instantiated. boost::asio::io_context ioc; - boost::asio::io_service::strand s{ioc}; + boost::asio::strand< + boost::asio::io_context::executor_type> s( + ioc.get_executor()); stream ws{ioc}; - ws.async_ping({}, s.wrap(copyable_handler{})); + ws.async_ping({}, boost::asio::bind_executor( + s, copyable_handler{})); } void diff --git a/test/beast/websocket/read2.cpp b/test/beast/websocket/read2.cpp index e363ffc4..933a1701 100644 --- a/test/beast/websocket/read2.cpp +++ b/test/beast/websocket/read2.cpp @@ -12,7 +12,7 @@ #include "test.hpp" -#include +#include #include #include @@ -666,10 +666,13 @@ public: // it is instantiated. { boost::asio::io_context ioc; - boost::asio::io_service::strand s{ioc}; + boost::asio::strand< + boost::asio::io_context::executor_type> s( + ioc.get_executor()); stream ws{ioc}; flat_buffer b; - ws.async_read(b, s.wrap(copyable_handler{})); + ws.async_read(b, boost::asio::bind_executor( + s, copyable_handler{})); } } diff --git a/test/beast/websocket/write.cpp b/test/beast/websocket/write.cpp index 40385597..4109796e 100644 --- a/test/beast/websocket/write.cpp +++ b/test/beast/websocket/write.cpp @@ -10,7 +10,7 @@ // Test that header file is self-contained. #include -#include +#include #include #include "test.hpp" @@ -659,11 +659,14 @@ public: // it is instantiated. { boost::asio::io_context ioc; - boost::asio::io_service::strand s{ioc}; + boost::asio::strand< + boost::asio::io_context::executor_type> s( + ioc.get_executor()); stream ws{ioc}; flat_buffer b; ws.async_write(boost::asio::const_buffer{}, - s.wrap(copyable_handler{})); + boost::asio::bind_executor(s, + copyable_handler{})); } } diff --git a/test/doc/core_snippets.cpp b/test/doc/core_snippets.cpp index cf8bb1ef..78f67cdf 100644 --- a/test/doc/core_snippets.cpp +++ b/test/doc/core_snippets.cpp @@ -22,7 +22,6 @@ namespace doc_core_snippets { void fxx() { - //[snippet_core_1b // using namespace boost::beast; @@ -35,8 +34,9 @@ error_code ec; boost::asio::ip::tcp::socket sock{ioc}; //] + boost::ignore_unused(ec); -{ + { //[snippet_core_2 char const* const host = "www.example.com"; @@ -49,10 +49,12 @@ boost::asio::connect(stream, results.begin(), results.end()); // host and may be used to perform stream operations. //] -} + } } // fxx() +//------------------------------------------------------------------------------ + //[snippet_core_3 template diff --git a/test/doc/websocket_snippets.cpp b/test/doc/websocket_snippets.cpp index 9b27e76d..02c07ee2 100644 --- a/test/doc/websocket_snippets.cpp +++ b/test/doc/websocket_snippets.cpp @@ -32,6 +32,7 @@ auto work = boost::asio::make_work_guard(ioc); std::thread t{[&](){ ioc.run(); }}; error_code ec; boost::asio::ip::tcp::socket sock{ioc}; +boost::ignore_unused(ec); { //[ws_snippet_2 diff --git a/test/extras/include/boost/beast/test/test_allocator.hpp b/test/extras/include/boost/beast/test/test_allocator.hpp index ee472b0d..6dfabb0a 100644 --- a/test/extras/include/boost/beast/test/test_allocator.hpp +++ b/test/extras/include/boost/beast/test/test_allocator.hpp @@ -51,7 +51,7 @@ struct test_allocator_base static test_allocator select_on_container_copy_construction(test_allocator< - T, Equal, Assign, Move, Swap, true> const& a) + T, Equal, Assign, Move, Swap, true> const&) { return test_allocator{}; }