From e17a92f2a89369100ce45784516bacc2622167af Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 13 Dec 2018 16:43:17 -0800 Subject: [PATCH] Workarounds for msvc-14 --- CHANGELOG.md | 6 ++ Jamfile | 3 +- .../boost/beast/core/detail/buffers_pair.hpp | 75 ++++++++++++------- include/boost/beast/core/detail/tuple.hpp | 33 +++++++- .../boost/beast/core/impl/multi_buffer.hpp | 24 ++++++ .../boost/beast/core/impl/static_buffer.hpp | 68 ++++++++--------- test/beast/core/multi_buffer.cpp | 3 +- 7 files changed, 146 insertions(+), 66 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 738474ff..62eba45c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Version 199: + +* Workarounds for msvc-14 + +-------------------------------------------------------------------------------- + Version 198: * flat_buffer improvements diff --git a/Jamfile b/Jamfile index 6ec99363..db60ae95 100644 --- a/Jamfile +++ b/Jamfile @@ -103,7 +103,8 @@ project /boost/beast BOOST_ASIO_DISABLE_BOOST_DATE_TIME=1 BOOST_ASIO_DISABLE_BOOST_REGEX=1 BOOST_COROUTINES_NO_DEPRECATION_WARNING=1 - msvc:"/bigobj /permissive-" + msvc:"/bigobj" + msvc-14.1:"/permissive-" msvc:_SCL_SECURE_NO_WARNINGS=1 msvc:_CRT_SECURE_NO_WARNINGS=1 msvc:_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING diff --git a/include/boost/beast/core/detail/buffers_pair.hpp b/include/boost/beast/core/detail/buffers_pair.hpp index 7a77aaa5..8b557cd8 100644 --- a/include/boost/beast/core/detail/buffers_pair.hpp +++ b/include/boost/beast/core/detail/buffers_pair.hpp @@ -12,58 +12,76 @@ #include #include +#include #include namespace boost { namespace beast { namespace detail { -template +#if BOOST_WORKAROUND(BOOST_MSVC, < 1910) +# pragma warning (push) +# pragma warning (disable: 4521) // multiple copy constructors specified +# pragma warning (disable: 4522) // multiple assignment operators specified +#endif + +template class buffers_pair { - template - friend class buffers_pair; - public: // VFALCO: This type is public otherwise // asio::buffers_iterator won't compile. using value_type = typename - std::conditional::type; using const_iterator = value_type const*; buffers_pair() = default; - buffers_pair(buffers_pair const&) = default; - buffers_pair& operator=(buffers_pair const&) = default; - - template< - bool IsMutable_ = IsMutable, - class = typename - std::enable_if::type> - buffers_pair( - buffers_pair const& other) noexcept - : b_{other.b_[0], other.b_[1]} +#if defined(BOOST_MSVC) && BOOST_MSVC < 1910 + buffers_pair(buffers_pair const& other) + : buffers_pair( + *other.begin(), *(other.begin() + 1)) { } - template< - bool IsMutable_ = IsMutable, - class = typename - std::enable_if::type> - buffers_pair& operator=( - buffers_pair const& other) noexcept + buffers_pair& + operator=(buffers_pair const& other) { - b_ = {other.b_[0], other.b_[1]}; + b_[0] = *other.begin(); + b_[1] = *(other.begin() + 1); return *this; } +#else + buffers_pair(buffers_pair const& other) = default; + buffers_pair& operator=(buffers_pair const& other) = default; +#endif - value_type& - operator[](int i) noexcept + template< + bool isMutable_ = isMutable, + class = typename std::enable_if< + ! isMutable_>::type> + buffers_pair(buffers_pair const& other) + : buffers_pair( + *other.begin(), *(other.begin() + 1)) + { + } + + template< + bool isMutable_ = isMutable, + class = typename std::enable_if< + ! isMutable_>::type> + buffers_pair& + operator=(buffers_pair const& other) + { + b_[0] = *other.begin(); + b_[1] = *(other.begin() + 1); + } + + buffers_pair(value_type b0, value_type b1) + : b_{b0, b1} { - BOOST_ASSERT(i >= 0 && i < 2); - return b_[i]; } const_iterator @@ -79,10 +97,15 @@ public: return &b_[2]; return &b_[1]; } + private: value_type b_[2]; }; +#if BOOST_WORKAROUND(BOOST_MSVC, < 1910) +# pragma warning (pop) +#endif + } // detail } // beast } // boost diff --git a/include/boost/beast/core/detail/tuple.hpp b/include/boost/beast/core/detail/tuple.hpp index cb64b8b3..4c1098ba 100644 --- a/include/boost/beast/core/detail/tuple.hpp +++ b/include/boost/beast/core/detail/tuple.hpp @@ -25,6 +25,27 @@ template struct tuple_element_impl { T t; + + tuple_element_impl(T const& t_) + : t(t_) + { + } + + tuple_element_impl(T&& t_) + : t(std::move(t_)) + { + } +}; + +template +struct tuple_element_impl +{ + T& t; + + tuple_element_impl(T& t_) + : t(t_) + { + } }; template @@ -32,12 +53,13 @@ struct tuple_impl; template struct tuple_impl< - boost::mp11::index_sequence, Ts...> + boost::mp11::index_sequence, Ts...> : tuple_element_impl... { template explicit tuple_impl(Us&&... us) - : tuple_element_impl{std::forward(us)}... + : tuple_element_impl( + std::forward(us))... { } }; @@ -76,6 +98,13 @@ get(tuple_element_impl&& te) return std::move(te.t); } +template +T& +get(tuple_element_impl&& te) +{ + return te.t; +} + template using tuple_element = typename boost::copy_cv< mp11::mp_at_c::type, I>, T>::type; diff --git a/include/boost/beast/core/impl/multi_buffer.hpp b/include/boost/beast/core/impl/multi_buffer.hpp index f11b8303..8bc73e3c 100644 --- a/include/boost/beast/core/impl/multi_buffer.hpp +++ b/include/boost/beast/core/impl/multi_buffer.hpp @@ -11,6 +11,7 @@ #define BOOST_BEAST_IMPL_MULTI_BUFFER_HPP #include +#include #include #include #include @@ -125,6 +126,12 @@ public: //------------------------------------------------------------------------------ +#if BOOST_WORKAROUND(BOOST_MSVC, < 1910) +# pragma warning (push) +# pragma warning (disable: 4521) // multiple copy constructors specified +# pragma warning (disable: 4522) // multiple assignment operators specified +#endif + template template class basic_multi_buffer::readable_bytes @@ -149,8 +156,21 @@ public: class const_iterator; readable_bytes() = delete; +#if ! defined(_MSC_VER) || (_MSC_VER >= 1910) readable_bytes(readable_bytes const&) = default; readable_bytes& operator=(readable_bytes const&) = default; +#else + readable_bytes(readable_bytes const& other) + : b_(other.b_) + { + } + + readable_bytes& operator=(readable_bytes const& other) + { + b_ = other.b_; + return *this; + } +#endif template< bool IsMutable_ = IsMutable, @@ -182,6 +202,10 @@ public: } }; +#if BOOST_WORKAROUND(BOOST_MSVC, < 1910) +# pragma warning (pop) +#endif + //------------------------------------------------------------------------------ template diff --git a/include/boost/beast/core/impl/static_buffer.hpp b/include/boost/beast/core/impl/static_buffer.hpp index 68a3b129..e272e37c 100644 --- a/include/boost/beast/core/impl/static_buffer.hpp +++ b/include/boost/beast/core/impl/static_buffer.hpp @@ -34,19 +34,17 @@ static_buffer_base:: data() const noexcept -> const_buffers_type { - using net::const_buffer; - const_buffers_type result; if(in_off_ + in_size_ <= capacity_) - { - result[0] = const_buffer{begin_ + in_off_, in_size_}; - result[1] = const_buffer{begin_, 0}; - } - else - { - result[0] = const_buffer{begin_ + in_off_, capacity_ - in_off_}; - result[1] = const_buffer{begin_, in_size_ - (capacity_ - in_off_)}; - } - return result; + return { + net::const_buffer{ + begin_ + in_off_, in_size_}, + net::const_buffer{ + begin_, 0}}; + return { + net::const_buffer{ + begin_ + in_off_, capacity_ - in_off_}, + net::const_buffer{ + begin_, in_size_ - (capacity_ - in_off_)}}; } auto @@ -54,19 +52,17 @@ static_buffer_base:: data() noexcept -> mutable_data_type { - using net::mutable_buffer; - mutable_data_type result; if(in_off_ + in_size_ <= capacity_) - { - result[0] = mutable_buffer{begin_ + in_off_, in_size_}; - result[1] = mutable_buffer{begin_, 0}; - } - else - { - result[0] = mutable_buffer{begin_ + in_off_, capacity_ - in_off_}; - result[1] = mutable_buffer{begin_, in_size_ - (capacity_ - in_off_)}; - } - return result; + return { + net::mutable_buffer{ + begin_ + in_off_, in_size_}, + net::mutable_buffer{ + begin_, 0}}; + return { + net::mutable_buffer{ + begin_ + in_off_, capacity_ - in_off_}, + net::mutable_buffer{ + begin_, in_size_ - (capacity_ - in_off_)}}; } auto @@ -79,19 +75,19 @@ prepare(std::size_t n) -> BOOST_THROW_EXCEPTION(std::length_error{ "buffer overflow"}); out_size_ = n; - auto const out_off = (in_off_ + in_size_) % capacity_; - mutable_buffers_type result; + auto const out_off = + (in_off_ + in_size_) % capacity_; if(out_off + out_size_ <= capacity_ ) - { - result[0] = mutable_buffer{begin_ + out_off, out_size_}; - result[1] = mutable_buffer{begin_, 0}; - } - else - { - result[0] = mutable_buffer{begin_ + out_off, capacity_ - out_off}; - result[1] = mutable_buffer{begin_, out_size_ - (capacity_ - out_off)}; - } - return result; + return { + net::mutable_buffer{ + begin_ + out_off, out_size_}, + net::mutable_buffer{ + begin_, 0}}; + return { + net::mutable_buffer{ + begin_ + out_off, capacity_ - out_off}, + net::mutable_buffer{ + begin_, out_size_ - (capacity_ - out_off)}}; } void diff --git a/test/beast/core/multi_buffer.cpp b/test/beast/core/multi_buffer.cpp index 87846eca..d259a39f 100644 --- a/test/beast/core/multi_buffer.cpp +++ b/test/beast/core/multi_buffer.cpp @@ -46,7 +46,8 @@ public: BOOST_STATIC_ASSERT(std::is_convertible< multi_buffer::mutable_data_type, multi_buffer::const_buffers_type>::value); -#if ! defined( BOOST_LIBSTDCXX_VERSION ) || BOOST_LIBSTDCXX_VERSION >= 50000 +#if ! BOOST_WORKAROUND(BOOST_LIBSTDCXX_VERSION, < 50000) && \ + ! BOOST_WORKAROUND(BOOST_MSVC, < 1910) BOOST_STATIC_ASSERT(std::is_trivially_copyable< multi_buffer::const_buffers_type>::value); BOOST_STATIC_ASSERT(std::is_trivially_copyable<