Skip to content

Commit 9c0f914

Browse files
committed
Workaround Boost.Optional 1.56.0 MSVC 2010 Issue
This change takes the advice of the Boost.Optional maintainer when working around the breaking changes in Boost.Optional 1.56.0 -- apparently MSVC has a bug in copy-construction resolution which considers multiple conversions (not a standard-conforming extension) and because of changes to the Boost.Optional interface is being hit. This commit only works around the MSVC 2010 compiler. It may be that the bug is also in newer versions of the compiler, but that I'm less sure about.
1 parent 731a7a8 commit 9c0f914

File tree

1 file changed

+21
-5
lines changed
  • boost/network/protocol/http/message/wrappers

1 file changed

+21
-5
lines changed

boost/network/protocol/http/message/wrappers/port.hpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_PORT_HPP_20100618
22
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_PORT_HPP_20100618
33

4-
// Copyright 2010 (c) Dean Michael Berris.
4+
// Copyright 2010, 2014 Dean Michael Berris <dberris@google.com>
55
// Copyright 2010 (c) Sinefunc, Inc.
6+
// Copyright 2014 Google, Inc.
67
// Distributed under the Boost Software License, Version 1.0.
78
// (See accompanying file LICENSE_1_0.txt or copy at
89
// http://www.boost.org/LICENSE_1_0.txt)
910

1011
#include <boost/optional.hpp>
12+
#include <boost/cstdint.hpp>
13+
#include <boost/network/uri/accessors.hpp>
1114

1215
namespace boost {
1316
namespace network {
@@ -26,11 +29,26 @@ struct port_wrapper {
2629

2730
typedef typename basic_request<Tag>::port_type port_type;
2831

29-
operator port_type() { return message_.port(); }
32+
operator port_type() const { return message_.port(); }
3033

31-
operator boost::optional<boost::uint16_t>() {
34+
#if (_MSC_VER == 1600)
35+
// We hack this so that we don't run into the issue of MSVC 2010 not doing the
36+
// right thing when converting/copying Boost.Optional objects.
37+
struct optional_wrapper {
38+
boost::optional<boost::uint16_t> o_;
39+
explicit optional_wrapper(boost::optional<boost::uint16_t> o) : o_(o) {}
40+
operator boost::optional<boost::uint16_t>() { return o_; }
41+
};
42+
43+
operator optional_wrapper() const {
44+
return optional_wrapper(uri::port_us(message_.uri()));
45+
}
46+
#else
47+
operator boost::optional<boost::uint16_t>() const {
3248
return uri::port_us(message_.uri());
3349
}
50+
#endif
51+
3452
};
3553

3654
} // namespace impl
@@ -41,9 +59,7 @@ inline impl::port_wrapper<Tag> port(basic_request<Tag> const& request) {
4159
}
4260

4361
} // namespace http
44-
4562
} // namespace network
46-
4763
} // namespace boost
4864

4965
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_PORT_HPP_20100618

0 commit comments

Comments
 (0)