From 58d42cc803b78b5d5cf8d835b1dd537040de0329 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 26 Jun 2017 17:20:42 -0700 Subject: [PATCH] Use BEAST_FALLTHROUGH to silence warnings fix #545 --- CHANGELOG.md | 1 + include/beast/core/detail/config.hpp | 20 +++++++++++++++++++ .../beast/core/impl/buffered_read_stream.ipp | 4 ++-- include/beast/http/impl/basic_parser.ipp | 10 +++++----- include/beast/http/impl/serializer.ipp | 18 ++++++++--------- include/beast/http/impl/status.ipp | 10 +++++----- include/beast/http/impl/verb.ipp | 8 ++++---- include/beast/http/impl/write.ipp | 4 ++-- include/beast/websocket/impl/close.ipp | 4 ++-- include/beast/websocket/impl/ping.ipp | 4 ++-- include/beast/websocket/impl/read.ipp | 5 +++-- include/beast/websocket/impl/write.ipp | 13 ++++++------ test/benchmarks/nodejs_parser.cpp | 10 ++++++++++ 13 files changed, 72 insertions(+), 39 deletions(-) create mode 100644 include/beast/core/detail/config.hpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 38da6722..e247545e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 69: * basic_parser optimizations +* Use BEAST_FALLTHROUGH to silence warnings -------------------------------------------------------------------------------- diff --git a/include/beast/core/detail/config.hpp b/include/beast/core/detail/config.hpp new file mode 100644 index 00000000..100348cc --- /dev/null +++ b/include/beast/core/detail/config.hpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef BEAST_CORE_DETAIL_CONFIG_HPP +#define BEAST_CORE_DETAIL_CONFIG_HPP + +#include +#include + +#if BOOST_VERSION >= 106500 || ! defined(BOOST_GCC) || BOOST_GCC < 70000 +# define BEAST_FALLTHROUGH BOOST_FALLTHROUGH +#else +# define BEAST_FALLTHROUGH _attribute__((fallthrough)) +#endif + +#endif diff --git a/include/beast/core/impl/buffered_read_stream.ipp b/include/beast/core/impl/buffered_read_stream.ipp index 027b4f02..d78c1361 100644 --- a/include/beast/core/impl/buffered_read_stream.ipp +++ b/include/beast/core/impl/buffered_read_stream.ipp @@ -12,11 +12,11 @@ #include #include #include +#include #include #include #include #include -#include namespace beast { @@ -121,7 +121,7 @@ read_some_op::operator()( case 2: s_.sb_.commit(bytes_transferred); - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case 3: bytes_transferred = diff --git a/include/beast/http/impl/basic_parser.ipp b/include/beast/http/impl/basic_parser.ipp index 809f06af..b9df7cb0 100644 --- a/include/beast/http/impl/basic_parser.ipp +++ b/include/beast/http/impl/basic_parser.ipp @@ -11,10 +11,10 @@ #include #include #include +#include #include #include #include -#include #include #include @@ -178,7 +178,7 @@ loop: return 0; } state_ = state::header; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case state::header: parse_header(p, n, ec); @@ -191,7 +191,7 @@ loop: if(ec) goto done; state_ = state::body; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case state::body: parse_body(p, n, ec); @@ -204,7 +204,7 @@ loop: if(ec) goto done; state_ = state::body_to_eof; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case state::body_to_eof: parse_body_to_eof(p, n, ec); @@ -217,7 +217,7 @@ loop: if(ec) goto done; state_ = state::chunk_header; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case state::chunk_header: parse_chunk_header(p, n, ec); diff --git a/include/beast/http/impl/serializer.ipp b/include/beast/http/impl/serializer.ipp index a7768da3..45617d03 100644 --- a/include/beast/http/impl/serializer.ipp +++ b/include/beast/http/impl/serializer.ipp @@ -10,8 +10,8 @@ #include #include +#include #include -#include #include namespace beast { @@ -63,7 +63,7 @@ get(error_code& ec, Visit&& visit) if(frd_->chunked()) goto go_init_c; s_ = do_init; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; } case do_init: @@ -86,7 +86,7 @@ get(error_code& ec, Visit&& visit) frd_->get(), result->first}; s_ = do_header; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; } case do_header: @@ -108,7 +108,7 @@ get(error_code& ec, Visit&& visit) return; } s_ = do_body + 1; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case do_body + 1: { @@ -120,7 +120,7 @@ get(error_code& ec, Visit&& visit) more_ = result->second; v_ = cb1_t{result->first}; s_ = do_body + 2; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; } case do_body + 2: @@ -162,7 +162,7 @@ get(error_code& ec, Visit&& visit) result->first, detail::chunk_crlf()}; s_ = do_header_c; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; } case do_header_c: @@ -184,7 +184,7 @@ get(error_code& ec, Visit&& visit) return; } s_ = do_body_c + 1; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case do_body_c + 1: { @@ -209,7 +209,7 @@ get(error_code& ec, Visit&& visit) result->first, detail::chunk_crlf()}; s_ = do_body_c + 2; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; } case do_body_c + 2: @@ -231,7 +231,7 @@ get(error_code& ec, Visit&& visit) }(), detail::chunk_crlf()}; s_ = do_final_c + 1; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case do_final_c + 1: visit(ec, boost::get(v_)); diff --git a/include/beast/http/impl/status.ipp b/include/beast/http/impl/status.ipp index a68058a3..671547c9 100644 --- a/include/beast/http/impl/status.ipp +++ b/include/beast/http/impl/status.ipp @@ -8,7 +8,7 @@ #ifndef BEAST_HTTP_IMPL_STATUS_IPP #define BEAST_HTTP_IMPL_STATUS_IPP -#include +#include #include namespace beast { @@ -25,7 +25,7 @@ int_to_status(unsigned v) case status::continue_: case status::switching_protocols: case status::processing: - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; // 2xx case status::ok: @@ -38,7 +38,7 @@ int_to_status(unsigned v) case status::multi_status: case status::already_reported: case status::im_used: - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; // 3xx case status::multiple_choices: @@ -49,7 +49,7 @@ int_to_status(unsigned v) case status::use_proxy: case status::temporary_redirect: case status::permanent_redirect: - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; // 4xx case status::bad_request: @@ -81,7 +81,7 @@ int_to_status(unsigned v) case status::connection_closed_without_response: case status::unavailable_for_legal_reasons: case status::client_closed_request: - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; // 5xx case status::internal_server_error: diff --git a/include/beast/http/impl/verb.ipp b/include/beast/http/impl/verb.ipp index a898d718..ad0f1b5c 100644 --- a/include/beast/http/impl/verb.ipp +++ b/include/beast/http/impl/verb.ipp @@ -8,7 +8,7 @@ #ifndef BEAST_HTTP_IMPL_VERB_IPP #define BEAST_HTTP_IMPL_VERB_IPP -#include +#include #include #include @@ -156,7 +156,7 @@ string_to_verb(string_view v) return verb::connect; if(eq(v, "PY")) return verb::copy; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; default: break; @@ -217,7 +217,7 @@ string_to_verb(string_view v) case 'O': if(eq(v, "VE")) return verb::move; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; default: break; @@ -261,7 +261,7 @@ string_to_verb(string_view v) return verb::purge; if(eq(v, "T")) return verb::put; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; default: break; diff --git a/include/beast/http/impl/write.ipp b/include/beast/http/impl/write.ipp index 2077611f..a723bd0e 100644 --- a/include/beast/http/impl/write.ipp +++ b/include/beast/http/impl/write.ipp @@ -14,11 +14,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include @@ -320,7 +320,7 @@ operator()(error_code ec, case 2: state_ = 3; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case 3: { diff --git a/include/beast/websocket/impl/close.ipp b/include/beast/websocket/impl/close.ipp index 620c72e2..807a8e29 100644 --- a/include/beast/websocket/impl/close.ipp +++ b/include/beast/websocket/impl/close.ipp @@ -11,10 +11,10 @@ #include #include #include +#include #include #include #include -#include #include #include @@ -154,7 +154,7 @@ operator()(error_code ec, bool again) return; } d.ws.wr_block_ = &d; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case 1: // send close frame diff --git a/include/beast/websocket/impl/ping.ipp b/include/beast/websocket/impl/ping.ipp index ac496f7b..4a0193a1 100644 --- a/include/beast/websocket/impl/ping.ipp +++ b/include/beast/websocket/impl/ping.ipp @@ -11,11 +11,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include @@ -153,7 +153,7 @@ operator()(error_code ec, bool again) return; } d.ws.wr_block_ = &d; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case 1: // send ping frame diff --git a/include/beast/websocket/impl/read.ipp b/include/beast/websocket/impl/read.ipp index 516f7466..e757bd43 100644 --- a/include/beast/websocket/impl/read.ipp +++ b/include/beast/websocket/impl/read.ipp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -523,7 +524,7 @@ operator()(error_code ec, ec = boost::asio::error::operation_aborted; goto upcall; } - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; //------------------------------------------------------------------ @@ -1070,7 +1071,7 @@ operator()(error_code const& ec, bool fin) case 1: state_ = 2; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case 2: if(ec) diff --git a/include/beast/websocket/impl/write.ipp b/include/beast/websocket/impl/write.ipp index 58c15c81..e6036fbf 100644 --- a/include/beast/websocket/impl/write.ipp +++ b/include/beast/websocket/impl/write.ipp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -231,7 +232,7 @@ operator()(error_code ec, case do_nomask_nofrag: BOOST_ASSERT(! d.ws.wr_block_); d.ws.wr_block_ = &d; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case do_nomask_nofrag + 1: { @@ -254,7 +255,7 @@ operator()(error_code ec, case do_nomask_frag: BOOST_ASSERT(! d.ws.wr_block_); d.ws.wr_block_ = &d; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case do_nomask_frag + 1: { @@ -302,7 +303,7 @@ operator()(error_code ec, case do_mask_nofrag: BOOST_ASSERT(! d.ws.wr_block_); d.ws.wr_block_ = &d; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case do_mask_nofrag + 1: { @@ -354,7 +355,7 @@ operator()(error_code ec, case do_mask_frag: BOOST_ASSERT(! d.ws.wr_block_); d.ws.wr_block_ = &d; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case do_mask_frag + 1: { @@ -407,7 +408,7 @@ operator()(error_code ec, case do_deflate: BOOST_ASSERT(! d.ws.wr_block_); d.ws.wr_block_ = &d; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case do_deflate + 1: { @@ -634,7 +635,7 @@ operator()(error_code ec) { case 2: d.step = 3; - BOOST_FALLTHROUGH; + BEAST_FALLTHROUGH; case 3: case 0: { diff --git a/test/benchmarks/nodejs_parser.cpp b/test/benchmarks/nodejs_parser.cpp index 633872fa..47397e7b 100644 --- a/test/benchmarks/nodejs_parser.cpp +++ b/test/benchmarks/nodejs_parser.cpp @@ -5,13 +5,23 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // +#if defined(__GNUC__) && (__GNUC__ >= 7) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" +#endif + #ifdef _MSC_VER # pragma warning (push) # pragma warning (disable: 4127) // conditional expression is constant # pragma warning (disable: 4244) // integer conversion, possible loss of data #endif + #include "nodejs-parser/http_parser.c" + #ifdef _MSC_VER # pragma warning (pop) #endif +#if defined(__GNUC__) && (__GNUC__ >= 7) +#pragma GCC diagnostic pop +#endif