Skip to content

Commit 0f65858

Browse files
committed
VS2013 incorrectly reports "warning C4573: the usage of 'symbol' requires the compiler to capture 'this' but the current default capture mode does not allow it"; the issue and workaround is the same as for GCC 4.7 in commit:5244af7c.
(cherry picked from commit d0ce63e)
1 parent c2f2388 commit 0f65858

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

Release/src/http/client/http_client_asio.cpp

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,33 @@
4444
#include <unordered_set>
4545
#include <memory>
4646

47+
#if defined(__GNUC__)
48+
49+
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
50+
#define AND_CAPTURE_MEMBER_FUNCTION_POINTERS
51+
#else
52+
// GCC Bug 56222 - Pointer to member in lambda should not require this to be captured
53+
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56222
54+
// GCC Bug 51494 - Legal program rejection - capturing "this" when using static method inside lambda
55+
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51494
56+
#define AND_CAPTURE_MEMBER_FUNCTION_POINTERS , this
57+
#endif
58+
59+
#elif defined(_MSC_VER)
60+
61+
#if _MSC_VER >= 1900
62+
#define AND_CAPTURE_MEMBER_FUNCTION_POINTERS
63+
#else
64+
// This bug also afflicts VS2013 which incorrectly reports "warning C4573: the usage of 'symbol' requires the compiler to capture 'this' but the current default capture mode does not allow it"
65+
#define AND_CAPTURE_MEMBER_FUNCTION_POINTERS , this
66+
#endif
67+
68+
#else
69+
70+
#define AND_CAPTURE_MEMBER_FUNCTION_POINTERS
71+
72+
#endif
73+
4774
using boost::asio::ip::tcp;
4875

4976
#ifdef __ANDROID__
@@ -620,7 +647,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
620647
proxy_host = utility::conversions::to_utf8string(proxy_uri.host());
621648
}
622649

623-
auto start_http_request_flow = [proxy_type, proxy_host, proxy_port](std::shared_ptr<asio_context> ctx)
650+
auto start_http_request_flow = [proxy_type, proxy_host, proxy_port AND_CAPTURE_MEMBER_FUNCTION_POINTERS](std::shared_ptr<asio_context> ctx)
624651
{
625652
if (ctx->m_request._cancellation_token().is_canceled())
626653
{
@@ -1010,7 +1037,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
10101037
auto readbuf = _get_readbuffer();
10111038
uint8_t *buf = boost::asio::buffer_cast<uint8_t *>(m_body_buf.prepare(chunkSize + http::details::chunked_encoding::additional_encoding_space));
10121039
const auto this_request = shared_from_this();
1013-
readbuf.getn(buf + http::details::chunked_encoding::data_offset, chunkSize).then([this_request, buf, chunkSize](pplx::task<size_t> op)
1040+
readbuf.getn(buf + http::details::chunked_encoding::data_offset, chunkSize).then([this_request, buf, chunkSize AND_CAPTURE_MEMBER_FUNCTION_POINTERS](pplx::task<size_t> op)
10141041
{
10151042
size_t readSize = 0;
10161043
try
@@ -1067,7 +1094,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
10671094
const auto this_request = shared_from_this();
10681095
const auto readSize = static_cast<size_t>(std::min(static_cast<uint64_t>(m_http_client->client_config().chunksize()), m_content_length - m_uploaded));
10691096
auto readbuf = _get_readbuffer();
1070-
readbuf.getn(boost::asio::buffer_cast<uint8_t *>(m_body_buf.prepare(readSize)), readSize).then([this_request](pplx::task<size_t> op)
1097+
readbuf.getn(boost::asio::buffer_cast<uint8_t *>(m_body_buf.prepare(readSize)), readSize).then([this_request AND_CAPTURE_MEMBER_FUNCTION_POINTERS](pplx::task<size_t> op)
10711098
{
10721099
try
10731100
{
@@ -1370,7 +1397,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
13701397
auto shared_decompressed = std::make_shared<data_buffer>(std::move(decompressed));
13711398

13721399
writeBuffer.putn_nocopy(shared_decompressed->data(), shared_decompressed->size())
1373-
.then([this_request, to_read, shared_decompressed](pplx::task<size_t> op)
1400+
.then([this_request, to_read, shared_decompressed AND_CAPTURE_MEMBER_FUNCTION_POINTERS](pplx::task<size_t> op)
13741401
{
13751402
try
13761403
{
@@ -1388,7 +1415,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
13881415
}
13891416
else
13901417
{
1391-
writeBuffer.putn_nocopy(boost::asio::buffer_cast<const uint8_t *>(m_body_buf.data()), to_read).then([this_request, to_read](pplx::task<size_t> op)
1418+
writeBuffer.putn_nocopy(boost::asio::buffer_cast<const uint8_t *>(m_body_buf.data()), to_read).then([this_request, to_read AND_CAPTURE_MEMBER_FUNCTION_POINTERS](pplx::task<size_t> op)
13921419
{
13931420
try
13941421
{
@@ -1485,7 +1512,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
14851512
auto shared_decompressed = std::make_shared<data_buffer>(std::move(decompressed));
14861513

14871514
writeBuffer.putn_nocopy(shared_decompressed->data(), shared_decompressed->size())
1488-
.then([this_request, read_size, shared_decompressed](pplx::task<size_t> op)
1515+
.then([this_request, read_size, shared_decompressed AND_CAPTURE_MEMBER_FUNCTION_POINTERS](pplx::task<size_t> op)
14891516
{
14901517
size_t writtenSize = 0;
14911518
try
@@ -1507,7 +1534,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
15071534
else
15081535
{
15091536
writeBuffer.putn_nocopy(boost::asio::buffer_cast<const uint8_t *>(m_body_buf.data()), read_size)
1510-
.then([this_request](pplx::task<size_t> op)
1537+
.then([this_request AND_CAPTURE_MEMBER_FUNCTION_POINTERS](pplx::task<size_t> op)
15111538
{
15121539
size_t writtenSize = 0;
15131540
try
@@ -1558,7 +1585,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
15581585

15591586
m_timer.expires_from_now(m_duration);
15601587
auto ctx = m_ctx;
1561-
m_timer.async_wait([ctx](const boost::system::error_code& ec)
1588+
m_timer.async_wait([ctx AND_CAPTURE_MEMBER_FUNCTION_POINTERS](const boost::system::error_code& ec)
15621589
{
15631590
handle_timeout(ec, ctx);
15641591
});
@@ -1573,7 +1600,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
15731600
// The existing handler was canceled so schedule a new one.
15741601
assert(m_state == started);
15751602
auto ctx = m_ctx;
1576-
m_timer.async_wait([ctx](const boost::system::error_code& ec)
1603+
m_timer.async_wait([ctx AND_CAPTURE_MEMBER_FUNCTION_POINTERS](const boost::system::error_code& ec)
15771604
{
15781605
handle_timeout(ec, ctx);
15791606
});

0 commit comments

Comments
 (0)