diff --git a/doc/changelog.adoc b/doc/changelog.adoc index e6dca5e..8286c44 100644 --- a/doc/changelog.adoc +++ b/doc/changelog.adoc @@ -23,4 +23,5 @@ Changes prepared for WebCPP's independent Cobalt integration. * Fixed SSL transfer cancellation and socket ownership after moving streams. * Fixed the shipped Wasm IPv6 UDP protocol constant; native Boost behavior remains documented. * Added target configuration, application matrices and Release performance and memory documentation. +* Changed the shipped Wasm and native SSL functions returning `boost::system::result` to `+[[nodiscard]]+`. // end::unreleased[] diff --git a/include/webcpp/cobalt/detail/backend/channel.hpp b/include/webcpp/cobalt/detail/backend/channel.hpp index 12fedc9..e062d6d 100644 --- a/include/webcpp/cobalt/detail/backend/channel.hpp +++ b/include/webcpp/cobalt/detail/backend/channel.hpp @@ -105,7 +105,7 @@ struct channel std::coroutine_handle await_suspend(std::coroutine_handle h); T await_resume(); std::tuple<::boost::system::error_code, T> await_resume(const struct as_tuple_tag & ); - ::boost::system::result await_resume(const struct as_result_tag &); + [[nodiscard]] ::boost::system::result await_resume(const struct as_result_tag &); explicit operator bool() const {return chn && chn->is_open();} }; @@ -149,7 +149,7 @@ struct channel std::coroutine_handle await_suspend(std::coroutine_handle h); void await_resume(); std::tuple<::boost::system::error_code> await_resume(const struct as_tuple_tag & ); - ::boost::system::result await_resume(const struct as_result_tag &); + [[nodiscard]] ::boost::system::result await_resume(const struct as_result_tag &); explicit operator bool() const {return chn && chn->is_open();} }; @@ -271,7 +271,7 @@ struct channel std::coroutine_handle await_suspend(std::coroutine_handle h); WEBCPP_COBALT_BACKEND_DECL void await_resume(); WEBCPP_COBALT_BACKEND_DECL std::tuple<::boost::system::error_code> await_resume(const struct as_tuple_tag & ); - WEBCPP_COBALT_BACKEND_DECL ::boost::system::result await_resume(const struct as_result_tag &); + [[nodiscard]] WEBCPP_COBALT_BACKEND_DECL ::boost::system::result await_resume(const struct as_result_tag &); explicit operator bool() const {return chn && chn->is_open();} }; @@ -313,7 +313,7 @@ struct channel WEBCPP_COBALT_BACKEND_DECL void await_resume(); WEBCPP_COBALT_BACKEND_DECL std::tuple<::boost::system::error_code> await_resume(const struct as_tuple_tag & ); - WEBCPP_COBALT_BACKEND_DECL ::boost::system::result await_resume(const struct as_result_tag &); + [[nodiscard]] WEBCPP_COBALT_BACKEND_DECL ::boost::system::result await_resume(const struct as_result_tag &); explicit operator bool() const {return chn && chn->is_open();} }; diff --git a/include/webcpp/cobalt/detail/backend/detail/generator.hpp b/include/webcpp/cobalt/detail/backend/detail/generator.hpp index e28e725..7aa4a8f 100644 --- a/include/webcpp/cobalt/detail/backend/detail/generator.hpp +++ b/include/webcpp/cobalt/detail/backend/detail/generator.hpp @@ -266,7 +266,7 @@ struct generator_receiver : generator_receiver_base return {nullptr, res.value()}; } - ::boost::system::result await_resume(const as_result_tag& ) + [[nodiscard]] ::boost::system::result await_resume(const as_result_tag& ) { if (cl.is_connected()) cl.clear(); diff --git a/include/webcpp/cobalt/detail/backend/detail/promise.hpp b/include/webcpp/cobalt/detail/backend/detail/promise.hpp index 9e28d72..ec4b29e 100644 --- a/include/webcpp/cobalt/detail/backend/detail/promise.hpp +++ b/include/webcpp/cobalt/detail/backend/detail/promise.hpp @@ -47,7 +47,7 @@ struct promise_value_holder std::optional result; bool result_taken = false; - ::boost::system::result get_result_value() + [[nodiscard]] ::boost::system::result get_result_value() { result_taken = true; BOOST_ASSERT(result); @@ -74,7 +74,7 @@ template<> struct promise_value_holder { bool result_taken = false; - ::boost::system::result get_result_value() + [[nodiscard]] ::boost::system::result get_result_value() { result_taken = true; return {::boost::system::in_place_value}; @@ -92,7 +92,7 @@ template struct promise_receiver : promise_value_holder { std::exception_ptr exception; - ::boost::system::result get_result() + [[nodiscard]] ::boost::system::result get_result() { if (exception && !done) // detached error return {::boost::system::in_place_error, std::exchange(exception, nullptr)}; @@ -220,7 +220,7 @@ struct promise_receiver : promise_value_holder return self->get_result().value(loc); } - ::boost::system::result await_resume(const as_result_tag &) + [[nodiscard]] ::boost::system::result await_resume(const as_result_tag &) { if (cl.is_connected()) cl.clear(); diff --git a/include/webcpp/cobalt/detail/backend/detail/task.hpp b/include/webcpp/cobalt/detail/backend/detail/task.hpp index 19dcabd..7dbde7e 100644 --- a/include/webcpp/cobalt/detail/backend/detail/task.hpp +++ b/include/webcpp/cobalt/detail/backend/detail/task.hpp @@ -46,7 +46,7 @@ struct task_value_holder std::optional result; bool result_taken = false; - ::boost::system::result get_result_value() + [[nodiscard]] ::boost::system::result get_result_value() { result_taken = true; BOOST_ASSERT(result); @@ -72,7 +72,7 @@ template<> struct task_value_holder { bool result_taken = false; - ::boost::system::result get_result_value() + [[nodiscard]] ::boost::system::result get_result_value() { result_taken = true; return {::boost::system::in_place_value}; @@ -92,7 +92,7 @@ template struct task_receiver : task_value_holder { std::exception_ptr exception; - ::boost::system::result get_result() + [[nodiscard]] ::boost::system::result get_result() { if (exception && !done) // detached error return {::boost::system::in_place_error, std::exchange(exception, nullptr)}; @@ -204,7 +204,7 @@ struct task_receiver : task_value_holder return self->get_result().value(loc); } - ::boost::system::result await_resume(const as_result_tag &) + [[nodiscard]] ::boost::system::result await_resume(const as_result_tag &) { if (cl.is_connected()) cl.clear(); diff --git a/include/webcpp/cobalt/detail/backend/detail/thread.hpp b/include/webcpp/cobalt/detail/backend/detail/thread.hpp index 16f2111..ceb4395 100644 --- a/include/webcpp/cobalt/detail/backend/detail/thread.hpp +++ b/include/webcpp/cobalt/detail/backend/detail/thread.hpp @@ -180,7 +180,7 @@ struct thread_awaitable std::rethrow_exception(ee); } - ::boost::system::result await_resume(const as_result_tag &) + [[nodiscard]] ::boost::system::result await_resume(const as_result_tag &) { if (cl.is_connected()) cl.clear(); diff --git a/include/webcpp/cobalt/detail/backend/io/acceptor.hpp b/include/webcpp/cobalt/detail/backend/io/acceptor.hpp index 3ba462c..755af90 100644 --- a/include/webcpp/cobalt/detail/backend/io/acceptor.hpp +++ b/include/webcpp/cobalt/detail/backend/io/acceptor.hpp @@ -27,8 +27,8 @@ struct BOOST_SYMBOL_VISIBLE acceptor WEBCPP_COBALT_BACKEND_IO_DECL acceptor(const ::webcpp::cobalt::executor & executor = this_thread::get_executor()); WEBCPP_COBALT_BACKEND_IO_DECL acceptor(endpoint ep, const ::webcpp::cobalt::executor & executor = this_thread::get_executor()); - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result bind(endpoint ep); - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result listen(int backlog = max_listen_connections); // int backlog = net::max_backlog() + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result bind(endpoint ep); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result listen(int backlog = max_listen_connections); // int backlog = net::max_backlog() WEBCPP_COBALT_BACKEND_IO_DECL endpoint local_endpoint(); private: struct WEBCPP_COBALT_BACKEND_IO_DECL accept_op final : op<::boost::system::error_code> diff --git a/include/webcpp/cobalt/detail/backend/io/datagram_socket.hpp b/include/webcpp/cobalt/detail/backend/io/datagram_socket.hpp index 35896d8..6826a93 100644 --- a/include/webcpp/cobalt/detail/backend/io/datagram_socket.hpp +++ b/include/webcpp/cobalt/detail/backend/io/datagram_socket.hpp @@ -49,7 +49,7 @@ struct BOOST_SYMBOL_VISIBLE datagram_socket final : socket #if defined(WEBCPP_ASIO_BACKEND_HAS_LOCAL_SOCKETS) -inline ::boost::system::result> make_pair(decltype(local_datagram) protocol) +[[nodiscard]] inline ::boost::system::result> make_pair(decltype(local_datagram) protocol) { std::pair res; auto c = connect_pair(protocol, res.first, res.second); diff --git a/include/webcpp/cobalt/detail/backend/io/file.hpp b/include/webcpp/cobalt/detail/backend/io/file.hpp index a52894f..b8916c5 100644 --- a/include/webcpp/cobalt/detail/backend/io/file.hpp +++ b/include/webcpp/cobalt/detail/backend/io/file.hpp @@ -102,24 +102,24 @@ struct BOOST_SYMBOL_VISIBLE file #else using native_handle_type = ::webcpp::asio_backend::basic_file::native_handle_type; #endif - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result assign(const native_handle_type & native_file); - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result cancel(); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result assign(const native_handle_type & native_file); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result cancel(); WEBCPP_COBALT_BACKEND_IO_DECL executor get_executor(); WEBCPP_COBALT_BACKEND_IO_DECL bool is_open() const; - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result close(); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result close(); WEBCPP_COBALT_BACKEND_IO_DECL native_handle_type native_handle(); - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result open(const char * path, flags open_flags); - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result open(const std::string & path, flags open_flags); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result open(const char * path, flags open_flags); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result open(const std::string & path, flags open_flags); - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result release(); - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result resize(std::uint64_t n); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result release(); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result resize(std::uint64_t n); - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result size() const; - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result sync_all(); - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result sync_data(); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result size() const; + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result sync_all(); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result sync_data(); #if defined(WEBCPP_ASIO_BACKEND_HAS_FILE) file(::webcpp::asio_backend::basic_file & file) : file_(file) {} diff --git a/include/webcpp/cobalt/detail/backend/io/pipe.hpp b/include/webcpp/cobalt/detail/backend/io/pipe.hpp index 988351c..c7bb0d4 100644 --- a/include/webcpp/cobalt/detail/backend/io/pipe.hpp +++ b/include/webcpp/cobalt/detail/backend/io/pipe.hpp @@ -26,7 +26,7 @@ namespace webcpp::cobalt::io { -WEBCPP_COBALT_BACKEND_IO_DECL +[[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result> pipe( const executor & executor = this_thread::get_executor() ); @@ -40,16 +40,16 @@ struct BOOST_SYMBOL_VISIBLE readable_pipe final : read_stream WEBCPP_COBALT_BACKEND_IO_DECL readable_pipe(native_handle_type native_file, const ::webcpp::cobalt::executor & executor = this_thread::get_executor()); WEBCPP_COBALT_BACKEND_IO_DECL readable_pipe(readable_pipe && sf) noexcept; - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result assign(native_handle_type native_file); - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result cancel(); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result assign(native_handle_type native_file); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result cancel(); WEBCPP_COBALT_BACKEND_IO_DECL executor get_executor(); WEBCPP_COBALT_BACKEND_IO_DECL bool is_open() const; - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result close(); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result close(); WEBCPP_COBALT_BACKEND_IO_DECL native_handle_type native_handle(); - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result release(); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result release(); [[nodiscard]] WEBCPP_COBALT_BACKEND_MSVC_NOINLINE read_op read_some(mutable_buffer_sequence buffer) { @@ -75,8 +75,8 @@ struct BOOST_SYMBOL_VISIBLE writable_pipe final : write_stream WEBCPP_COBALT_BACKEND_IO_DECL writable_pipe(native_handle_type native_file, const ::webcpp::cobalt::executor & executor = this_thread::get_executor()); WEBCPP_COBALT_BACKEND_IO_DECL writable_pipe(writable_pipe && sf) noexcept; - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result assign(native_handle_type native_file); - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result cancel(); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result assign(native_handle_type native_file); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result cancel(); WEBCPP_COBALT_BACKEND_IO_DECL executor get_executor(); WEBCPP_COBALT_BACKEND_IO_DECL bool is_open() const; @@ -86,11 +86,11 @@ struct BOOST_SYMBOL_VISIBLE writable_pipe final : write_stream return {buffer, this, initiate_write_some_}; } - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result close(); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result close(); WEBCPP_COBALT_BACKEND_IO_DECL native_handle_type native_handle(); - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result release(); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result release(); private: WEBCPP_COBALT_BACKEND_IO_DECL static void initiate_write_some_(void *, const_buffer_sequence, webcpp::cobalt::completion_handler<::boost::system::error_code, std::size_t>); diff --git a/include/webcpp/cobalt/detail/backend/io/seq_packet_socket.hpp b/include/webcpp/cobalt/detail/backend/io/seq_packet_socket.hpp index 86ba38b..3962e23 100644 --- a/include/webcpp/cobalt/detail/backend/io/seq_packet_socket.hpp +++ b/include/webcpp/cobalt/detail/backend/io/seq_packet_socket.hpp @@ -84,7 +84,7 @@ struct BOOST_SYMBOL_VISIBLE seq_packet_socket final : socket }; -inline ::boost::system::result> make_pair(decltype(local_seqpacket) protocol) +[[nodiscard]] inline ::boost::system::result> make_pair(decltype(local_seqpacket) protocol) { std::pair res; auto c = connect_pair(protocol, res.first, res.second); diff --git a/include/webcpp/cobalt/detail/backend/io/serial_port.hpp b/include/webcpp/cobalt/detail/backend/io/serial_port.hpp index 7cd96e0..187560e 100644 --- a/include/webcpp/cobalt/detail/backend/io/serial_port.hpp +++ b/include/webcpp/cobalt/detail/backend/io/serial_port.hpp @@ -29,8 +29,8 @@ namespace webcpp::cobalt::io struct BOOST_SYMBOL_VISIBLE serial_port final : stream { - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result close(); - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result cancel(); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result close(); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result cancel(); WEBCPP_COBALT_BACKEND_IO_DECL bool is_open() const; [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result send_break(); diff --git a/include/webcpp/cobalt/detail/backend/io/socket.hpp b/include/webcpp/cobalt/detail/backend/io/socket.hpp index 478181f..93741ee 100644 --- a/include/webcpp/cobalt/detail/backend/io/socket.hpp +++ b/include/webcpp/cobalt/detail/backend/io/socket.hpp @@ -48,8 +48,8 @@ struct BOOST_SYMBOL_VISIBLE socket [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result remote_endpoint() const; - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result assign(protocol_type protocol, native_handle_type native_handle); - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result release(); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result assign(protocol_type protocol, native_handle_type native_handle); + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result release(); /// copied from what asio does [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result bytes_readable(); @@ -151,7 +151,7 @@ struct BOOST_SYMBOL_VISIBLE socket ::webcpp::asio_backend::basic_socket & socket_; }; -WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result connect_pair(protocol_type protocol, socket & socket1, socket & socket2); +[[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result connect_pair(protocol_type protocol, socket & socket1, socket & socket2); } diff --git a/include/webcpp/cobalt/detail/backend/io/ssl.hpp b/include/webcpp/cobalt/detail/backend/io/ssl.hpp index fefcf9a..a17a95e 100644 --- a/include/webcpp/cobalt/detail/backend/io/ssl.hpp +++ b/include/webcpp/cobalt/detail/backend/io/ssl.hpp @@ -81,7 +81,7 @@ struct BOOST_SYMBOL_VISIBLE stream final : private detail::stream_impl, socket, template requires requires (VerifyCallback & cb, ::webcpp::asio_backend::ssl::verify_context & ctx) {{cb(true, ctx)} -> std::same_as;} - ::boost::system::result set_verify_callback(VerifyCallback vc) + [[nodiscard]] ::boost::system::result set_verify_callback(VerifyCallback vc) { ::boost::system::error_code ec; stream_socket_.set_verify_callback(std::move(vc), ec); @@ -89,11 +89,11 @@ struct BOOST_SYMBOL_VISIBLE stream final : private detail::stream_impl, socket, } WEBCPP_COBALT_BACKEND_SSL_DECL - ::boost::system::result set_verify_depth(int depth); + [[nodiscard]] ::boost::system::result set_verify_depth(int depth); WEBCPP_COBALT_BACKEND_SSL_DECL - ::boost::system::result set_verify_mode(verify depth); + [[nodiscard]] ::boost::system::result set_verify_mode(verify depth); private: diff --git a/include/webcpp/cobalt/detail/backend/io/stream_file.hpp b/include/webcpp/cobalt/detail/backend/io/stream_file.hpp index cad2641..570b571 100644 --- a/include/webcpp/cobalt/detail/backend/io/stream_file.hpp +++ b/include/webcpp/cobalt/detail/backend/io/stream_file.hpp @@ -45,7 +45,7 @@ struct BOOST_SYMBOL_VISIBLE stream_file : file, stream { return {buffer, this, initiate_read_some_}; } - WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result seek( + [[nodiscard]] WEBCPP_COBALT_BACKEND_IO_DECL ::boost::system::result seek( std::int64_t offset, seek_basis whence); diff --git a/include/webcpp/cobalt/detail/backend/io/stream_socket.hpp b/include/webcpp/cobalt/detail/backend/io/stream_socket.hpp index b684bca..07aab48 100644 --- a/include/webcpp/cobalt/detail/backend/io/stream_socket.hpp +++ b/include/webcpp/cobalt/detail/backend/io/stream_socket.hpp @@ -52,7 +52,7 @@ struct BOOST_SYMBOL_VISIBLE stream_socket final : socket, stream #if defined(WEBCPP_ASIO_BACKEND_HAS_LOCAL_SOCKETS) -inline ::boost::system::result> make_pair(decltype(local_stream) protocol) +[[nodiscard]] inline ::boost::system::result> make_pair(decltype(local_stream) protocol) { std::pair res; auto c = connect_pair(protocol, res.first, res.second); diff --git a/include/webcpp/cobalt/detail/native_ssl.hpp b/include/webcpp/cobalt/detail/native_ssl.hpp index 4276a7e..8bf4894 100644 --- a/include/webcpp/cobalt/detail/native_ssl.hpp +++ b/include/webcpp/cobalt/detail/native_ssl.hpp @@ -75,7 +75,7 @@ struct BOOST_SYMBOL_VISIBLE stream final : private detail::stream_impl, socket, template requires requires (VerifyCallback & cb, asio::ssl::verify_context & ctx) {{cb(true, ctx)} -> std::same_as;} - ::boost::system::result set_verify_callback(VerifyCallback vc) + [[nodiscard]] ::boost::system::result set_verify_callback(VerifyCallback vc) { ::boost::system::error_code ec; stream_socket_.set_verify_callback(std::move(vc), ec); @@ -83,11 +83,11 @@ struct BOOST_SYMBOL_VISIBLE stream final : private detail::stream_impl, socket, } BOOST_COBALT_SSL_DECL - ::boost::system::result set_verify_depth(int depth); + [[nodiscard]] ::boost::system::result set_verify_depth(int depth); BOOST_COBALT_SSL_DECL - ::boost::system::result set_verify_mode(verify depth); + [[nodiscard]] ::boost::system::result set_verify_mode(verify depth); private: diff --git a/meta/lint.json b/meta/lint.json new file mode 100644 index 0000000..e21b477 --- /dev/null +++ b/meta/lint.json @@ -0,0 +1,3 @@ +{ + "nodiscard-results": "a dropped result, an I/O call's or an awaited operation's, would pass as a success" +} diff --git a/upstream/README.md b/upstream/README.md index c39da40..7a312c9 100644 --- a/upstream/README.md +++ b/upstream/README.md @@ -48,4 +48,8 @@ python3 upstream/sync.py --boost-include /path/to/boost/include --boost-source / Do not edit generated files. Original copyright and Boost Software License notices remain in every derived implementation. The generator also annotates two unused protocol tag parameters and scopes the Clang Wasm entry-point -diagnostic; these changes do not alter their API or runtime behavior. +diagnostic; these changes do not alter their API or runtime behavior. It +declares `[[nodiscard]]` every function of the shipped headers that returns +`boost::system::result`, which has no `[[nodiscard]]` of its own, so that a +dropped result is diagnosed rather than passing as a success; a friend +declaration cannot carry the attribute and keeps the first declaration's. diff --git a/upstream/generated.json b/upstream/generated.json index 4aaa660..21c205d 100644 --- a/upstream/generated.json +++ b/upstream/generated.json @@ -6,7 +6,7 @@ "include/webcpp/cobalt/detached.hpp": "71a27164545fe8861300abd3cf280a83c49780df4b0e632dc4411b28dc272c52", "include/webcpp/cobalt/detail/backend.hpp": "e031ecb7b904d296811aee6fd49fddfd643ee0d59ae86a12e1cfd9da369382b4", "include/webcpp/cobalt/detail/backend/async_for.hpp": "60a6a40042f5de9943ee5c38695bf390db6b58d56900544d35fb548ffb2e21d6", - "include/webcpp/cobalt/detail/backend/channel.hpp": "73a2275190ccc769119ebcf3756b3436dd382e73651adfcd6f525bbee4c12cb7", + "include/webcpp/cobalt/detail/backend/channel.hpp": "d8966f0ade483898ace0c14b3a488876c806d0e7e97d850431ff19ce53e8e202", "include/webcpp/cobalt/detail/backend/composition.hpp": "55cabd4359fccf27edc9bd509a4caab2533a00c42cba06f455b4b4b9087d368a", "include/webcpp/cobalt/detail/backend/concepts.hpp": "2a724694697892110b8e0bc54ab339540ceeacc87ba1f037f249daae743b5d99", "include/webcpp/cobalt/detail/backend/config.hpp": "ec735a5924f289c22e4c7074c3c5985d696e84b857ce55d59257ebae39ae8ab5", @@ -17,18 +17,18 @@ "include/webcpp/cobalt/detail/backend/detail/fork.hpp": "6194402ea442e292c7d0b21eb155714b3ac00732966170ced114bbfa5d219733", "include/webcpp/cobalt/detail/backend/detail/forward_cancellation.hpp": "ecaaacf05547d74417d13b354270c8c42974de88d7d468f3d40b1968fe8e4dfb", "include/webcpp/cobalt/detail/backend/detail/gather.hpp": "22a2c54c33820e3793fa025be3b669da9ade1a099a5e932be30f2f05fc27ba82", - "include/webcpp/cobalt/detail/backend/detail/generator.hpp": "0a36f3ad725b347f2161c130e7d4823b459c82fac6725b47f52f72108dfcac52", + "include/webcpp/cobalt/detail/backend/detail/generator.hpp": "282f90ad67508f04ea074153e4d5dfc3be8af32519db72622269d1e0b7ee77e0", "include/webcpp/cobalt/detail/backend/detail/handler.hpp": "ac2f340f21577e1fdcbb931473b055ea5099e1169470d2b5c58b2e475703c065", "include/webcpp/cobalt/detail/backend/detail/join.hpp": "f995c63d7c9d07e96e6d4932ef7fd69b657f5918d264126240bf49b952ce033d", "include/webcpp/cobalt/detail/backend/detail/main.hpp": "fab71c4a29b9c1de9d37b74092a282686eacf900b654a858850fb6eb8040f2e7", "include/webcpp/cobalt/detail/backend/detail/monotonic_resource.hpp": "7cb2bedd881a9f05f3ddd4eecb0ca0d026125dbf9f850ed5ccf30748a413df16", - "include/webcpp/cobalt/detail/backend/detail/promise.hpp": "b3a35afe5da4a431c79771e65a0c864d3f7bba80b6f1102e243062442458236f", + "include/webcpp/cobalt/detail/backend/detail/promise.hpp": "a9ca953ef55b3023f4e9f67d021f5737fabf3293c17e6e8860cca2276e3c88ac", "include/webcpp/cobalt/detail/backend/detail/race.hpp": "aefb8760d059742bbd49271ee8f6d8ca156e7a74369e0770aff15db216f56afa", "include/webcpp/cobalt/detail/backend/detail/sbo_resource.hpp": "eebd9983264c471ab4ac15d3b92fcdb00b0dfe5fb6deb138c98e5eb00cc76f90", "include/webcpp/cobalt/detail/backend/detail/spawn.hpp": "ae0dda4ba6505ed54155b36fe06b93125ad12a591b74d0720d726c704e542e7a", - "include/webcpp/cobalt/detail/backend/detail/task.hpp": "7a7c4bcaa40397060b6b83d1bdca7e75fcc44702abbb4d2d7d93b28bc5d22a38", + "include/webcpp/cobalt/detail/backend/detail/task.hpp": "b6df0475a87817de7795a8f68784446618c1152fda1cbfdf71f7cc6403783a28", "include/webcpp/cobalt/detail/backend/detail/this_thread.hpp": "cc0bd524c575cf07003fd254bd844a24100486c44d820dbf89553f18465d953c", - "include/webcpp/cobalt/detail/backend/detail/thread.hpp": "68e7cdc099154aa226d12cedcebafa415afb06fc1368e6b08f1b3a7cb832c049", + "include/webcpp/cobalt/detail/backend/detail/thread.hpp": "4cd198a6ca6c49f312fdb836665b4dc3311fc13c07f5178d92c984231b3cd869", "include/webcpp/cobalt/detail/backend/detail/util.hpp": "172276e8f8eb01f24f7d376e1e28ac0c78201ce4f3fbab4227ed2860b70471eb", "include/webcpp/cobalt/detail/backend/detail/wait_group.hpp": "c8be2e89838f781a68825438a32f8f918a55ac34362c8a98aee34f8609ea227c", "include/webcpp/cobalt/detail/backend/detail/with.hpp": "d451f528fe01b7740833fb16af0eb9e991ec8c338e776ddc431de81794b79880", @@ -41,28 +41,28 @@ "include/webcpp/cobalt/detail/backend/generator.hpp": "5ee27e97094bdaecbf8c845993ca2ab76d5120828a8844fbbca5a42173e6e688", "include/webcpp/cobalt/detail/backend/impl/channel.hpp": "86ff6c6bc926b5a770468f92d1050320523801ca762ddcf48163c136a75c2ad3", "include/webcpp/cobalt/detail/backend/io.hpp": "73c17b497a3087e869abd1abdf406af89f04f9f575eb49d0933ef770a9776908", - "include/webcpp/cobalt/detail/backend/io/acceptor.hpp": "2dd02157a900970cf5804ab012398ca954923d344221739961ae42e4ed288074", + "include/webcpp/cobalt/detail/backend/io/acceptor.hpp": "c5a8948af6803569afcd0b5c6d8190955021e6e2e5c66403a19ae8e7dc544c3f", "include/webcpp/cobalt/detail/backend/io/buffer.hpp": "8645a49b9478312240aed31f3286edfa6e25bfd206df70c3ce8190792155cca9", - "include/webcpp/cobalt/detail/backend/io/datagram_socket.hpp": "bd932dbc77bd27dab175b965e673aa162ccb7ac43d4c4e8b6d54ecde1426408c", + "include/webcpp/cobalt/detail/backend/io/datagram_socket.hpp": "789b3f1545729bee54c9dfefc314653746ffe3a3059f70e043baee316135782d", "include/webcpp/cobalt/detail/backend/io/detail/config.hpp": "72c5c9aa05039bbff60930bc4135d5d32ccbf70bbb13681910877cf5404bc351", "include/webcpp/cobalt/detail/backend/io/endpoint.hpp": "8b8407f2c1049b0d5147a2cf50d18ed0a37ac151e7e44d7ffc88507f5cf17d12", - "include/webcpp/cobalt/detail/backend/io/file.hpp": "7684a9d3d6218ed100e877a72c97f652a5b6e3f205ec536c5c29b691dda71b3f", + "include/webcpp/cobalt/detail/backend/io/file.hpp": "6776941e319150361edc3da74249333e7ed4b2b843ef97ccb789b6860422c243", "include/webcpp/cobalt/detail/backend/io/ops.hpp": "7ff8123cc011676faa6eeef44887f2fc13ae6e37958a43d223fa287b5bc344df", - "include/webcpp/cobalt/detail/backend/io/pipe.hpp": "3f9dd04d0eb964b532bf1d83552be6f5f0d135681b8d36e8d7feeddf68097358", + "include/webcpp/cobalt/detail/backend/io/pipe.hpp": "a2f7db1ef9a8f4ad439f37192965d3c6b3cf3fb5031e3029808448287d96ede0", "include/webcpp/cobalt/detail/backend/io/random_access_device.hpp": "d66fb5e26e0b86c941180c3fa6ee38ff61c05fd39d823b9bbf5d4a06f4fe554a", "include/webcpp/cobalt/detail/backend/io/random_access_file.hpp": "755d5e643cd58c0dca0161b0af314c2da4f58b5fd20484e3c8149825d0ed1438", "include/webcpp/cobalt/detail/backend/io/read.hpp": "b5f0b5cc5f9565aa16c269c35cb7de1a8249dc6db3ca67e36faed1bf31d2540b", "include/webcpp/cobalt/detail/backend/io/resolver.hpp": "7e36134c131ded274601b264a1f306ef69e84aba16de1f181eb491ad5593cacb", - "include/webcpp/cobalt/detail/backend/io/seq_packet_socket.hpp": "415c5697acadf2af6815df2b7852e706d0f80071dcb3d532c3d777a09688034e", - "include/webcpp/cobalt/detail/backend/io/serial_port.hpp": "811ce508a9f326084991e7c00b02a8d84cf7d89140e33565c2f1f2b38f13be08", + "include/webcpp/cobalt/detail/backend/io/seq_packet_socket.hpp": "df4e6f4e59f6d30e72604609f217670866677819f9596913a2a394b92c984f77", + "include/webcpp/cobalt/detail/backend/io/serial_port.hpp": "6e68677e6c82c3faeff5c2eb5d5b16d4378a106d893e15ea3843bf11cb706029", "include/webcpp/cobalt/detail/backend/io/signal_set.hpp": "67661e0987161a5e6ea0d2241772a802af04646c06155d88124042cd6e20f6d9", "include/webcpp/cobalt/detail/backend/io/sleep.hpp": "99f024e271f976fd69d3247b0b4bbd70db56516bb227d1cbf968bf1a10f86366", - "include/webcpp/cobalt/detail/backend/io/socket.hpp": "8524427946227230cfcf4decfa932e6343d2ebe16d6fc1089d9aeb46bd540177", - "include/webcpp/cobalt/detail/backend/io/ssl.hpp": "7dcdc64be907177896902cdf06c9be2c0edd4602ca7eee272b5803a54b313496", + "include/webcpp/cobalt/detail/backend/io/socket.hpp": "8ab251f1ccf5391272913dccd79d6b94ffb0d9ebfefca2b8b985caf08f8953e8", + "include/webcpp/cobalt/detail/backend/io/ssl.hpp": "801c91221503de3f5393d9d85d3e4c48d1451884840db72c3706744b28ca6f3f", "include/webcpp/cobalt/detail/backend/io/steady_timer.hpp": "e91737e54df831c4bff7a95b46f007d560641bf355dc1e2d55c6ab89c75c6abf", "include/webcpp/cobalt/detail/backend/io/stream.hpp": "94c17340101dc50a1a0574e329a56d3d554d4cb158094a302c22b6ed1a16e89c", - "include/webcpp/cobalt/detail/backend/io/stream_file.hpp": "4ba5effada5e9702585ea0039bff7bcbe85cf6c2319ef81763f6e387b7814c99", - "include/webcpp/cobalt/detail/backend/io/stream_socket.hpp": "2c7be1fa7ecbc902b12cc615f406ade40f47c4e6ab2ecc5662180035ffab1304", + "include/webcpp/cobalt/detail/backend/io/stream_file.hpp": "a234785b00b4a1be972961af4d1e0afa0f26ec308629242bc88872b787afa577", + "include/webcpp/cobalt/detail/backend/io/stream_socket.hpp": "b9742a4585a4354cabedfbd7bcd998f047624f2b853b199a5b57edb2b4415d7b", "include/webcpp/cobalt/detail/backend/io/system_timer.hpp": "0860ea01cef0c33638058ebff2d4269da0e05d07ffd4e0c4fffad6896c6113e9", "include/webcpp/cobalt/detail/backend/io/write.hpp": "4615fb1e439ce62879870e90394b64e9847eec21d7065dbcc65a4c9f2501ade0", "include/webcpp/cobalt/detail/backend/join.hpp": "1dee5f5e570bbb4f557d968cef90e16fe4216a93c92dd2ea93ef9d3feb50188f", @@ -81,7 +81,7 @@ "include/webcpp/cobalt/detail/backend/unique_handle.hpp": "1b92712eae2b29e6f63155b38d9814aa351aa3e51829cfcb1f292dc4d69dfc38", "include/webcpp/cobalt/detail/backend/wait_group.hpp": "4dd36e3c30ad0e0f73846887633db45655256e4f3214db38d6f28be3bf65474f", "include/webcpp/cobalt/detail/backend/with.hpp": "3b6557a5e863f028d7beb449d0dcd29e1cd73331718d73fb25155a1ab0c393ef", - "include/webcpp/cobalt/detail/native_ssl.hpp": "c1648d8e7e7e586070efd9be0502987397daed89b71ff2405f7575222f2c5d61", + "include/webcpp/cobalt/detail/native_ssl.hpp": "68cd7cc2eb9829efc567a23135ad18f258487dc2fb0d9dc7ebf4d1169df36410", "include/webcpp/cobalt/error.hpp": "f0e33416d59e8092283a009391029bc2bb29b8e2a3e35e51c122cd6d55f77619", "include/webcpp/cobalt/experimental/context.hpp": "077e0ba79e43f19c078c9a9aff95725cf89a91477ac175352179763e69cdbfea", "include/webcpp/cobalt/experimental/frame.hpp": "e4c47145d04f9e99056c12c95ecb8f0ea6ff5d03d572bdd67153a1761c88e7fa", diff --git a/upstream/sync.py b/upstream/sync.py index 7aea348..c39c81d 100644 --- a/upstream/sync.py +++ b/upstream/sync.py @@ -45,6 +45,38 @@ def relocate(text: str) -> str: return text.replace("BOOST_COBALT_", "WEBCPP_COBALT_BACKEND_") +# A declaration's leading return type, after the export macros and inline it may start with. +RESULT_DECLARATION = re.compile( + r"^\s*(?:WEBCPP_COBALT_BACKEND(?:_IO)?_DECL\s+|inline\s+)*::boost::system::result<" +) +EXPORT_MACRO = re.compile(r"\s*WEBCPP_COBALT_BACKEND(?:_IO)?_DECL\s*") + + +def mark_nodiscard(text: str) -> str: + """Declare [[nodiscard]] each function of a shipped header that returns + boost::system::result, which carries no [[nodiscard]] of its own: a dropped result would + pass as a success. A friend declaration is not a definition and cannot carry the attribute; + it redeclares a function marked at its first declaration.""" + lines = text.split("\n") + for index, line in enumerate(lines): + match = RESULT_DECLARATION.match(line) + if not match: + continue + depth, end = 0, match.end() - 1 + while end < len(line): + depth += {"<": 1, ">": -1}.get(line[end], 0) + if depth == 0: + break + end += 1 + if not re.match(r">\s*(?!operator\b)\w+\s*\(", line[end:]): + continue + target = index - 1 if index and EXPORT_MACRO.fullmatch(lines[index - 1]) else index + declaration = lines[target].lstrip() + indent = lines[target][: len(lines[target]) - len(declaration)] + lines[target] = indent + "[[nodiscard]] " + declaration + return "\n".join(lines) + + def outputs(headers: Path, sources: Path) -> dict[str, bytes]: pin = json.loads((BUNDLE / "pin.json").read_text()) original: dict[str, bytes] = {} @@ -120,6 +152,8 @@ def outputs(headers: Path, sources: Path) -> dict[str, bytes]: " // Plain TCP is allowed only", 1, ) + if destination.endswith(".hpp"): + ssl = mark_nodiscard(ssl) result[destination] = (banner + ssl).encode() for name, data in adapted.items(): text = relocate(data.decode()) @@ -228,6 +262,8 @@ def outputs(headers: Path, sources: Path) -> dict[str, bytes]: b"\n" b"#include ", ) + if path.startswith("include/"): + text = mark_nodiscard(text) result[path] = (banner + text).encode() source_names = sorted( name.removeprefix("libs/cobalt/src/")