44
44
#include < unordered_set>
45
45
#include < memory>
46
46
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
+
47
74
using boost::asio::ip::tcp;
48
75
49
76
#ifdef __ANDROID__
@@ -621,7 +648,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
621
648
proxy_host = utility::conversions::to_utf8string (proxy_uri.host ());
622
649
}
623
650
624
- auto start_http_request_flow = [proxy_type, proxy_host, proxy_port](std::shared_ptr<asio_context> ctx)
651
+ auto start_http_request_flow = [proxy_type, proxy_host, proxy_port AND_CAPTURE_MEMBER_FUNCTION_POINTERS ](std::shared_ptr<asio_context> ctx)
625
652
{
626
653
if (ctx->m_request ._cancellation_token ().is_canceled ())
627
654
{
@@ -1011,7 +1038,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
1011
1038
auto readbuf = _get_readbuffer ();
1012
1039
uint8_t *buf = boost::asio::buffer_cast<uint8_t *>(m_body_buf.prepare (chunkSize + http::details::chunked_encoding::additional_encoding_space));
1013
1040
const auto this_request = shared_from_this ();
1014
- readbuf.getn (buf + http::details::chunked_encoding::data_offset, chunkSize).then ([this_request, buf, chunkSize](pplx::task<size_t > op)
1041
+ 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)
1015
1042
{
1016
1043
size_t readSize = 0 ;
1017
1044
try
@@ -1068,7 +1095,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
1068
1095
const auto this_request = shared_from_this ();
1069
1096
const auto readSize = static_cast <size_t >(std::min (static_cast <uint64_t >(m_http_client->client_config ().chunksize ()), m_content_length - m_uploaded));
1070
1097
auto readbuf = _get_readbuffer ();
1071
- readbuf.getn (boost::asio::buffer_cast<uint8_t *>(m_body_buf.prepare (readSize)), readSize).then ([this_request](pplx::task<size_t > op)
1098
+ 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)
1072
1099
{
1073
1100
try
1074
1101
{
@@ -1371,7 +1398,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
1371
1398
auto shared_decompressed = std::make_shared<data_buffer>(std::move (decompressed));
1372
1399
1373
1400
writeBuffer.putn_nocopy (shared_decompressed->data (), shared_decompressed->size ())
1374
- .then ([this_request, to_read, shared_decompressed](pplx::task<size_t > op)
1401
+ .then ([this_request, to_read, shared_decompressed AND_CAPTURE_MEMBER_FUNCTION_POINTERS ](pplx::task<size_t > op)
1375
1402
{
1376
1403
try
1377
1404
{
@@ -1389,7 +1416,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
1389
1416
}
1390
1417
else
1391
1418
{
1392
- 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)
1419
+ 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)
1393
1420
{
1394
1421
try
1395
1422
{
@@ -1486,7 +1513,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
1486
1513
auto shared_decompressed = std::make_shared<data_buffer>(std::move (decompressed));
1487
1514
1488
1515
writeBuffer.putn_nocopy (shared_decompressed->data (), shared_decompressed->size ())
1489
- .then ([this_request, read_size, shared_decompressed](pplx::task<size_t > op)
1516
+ .then ([this_request, read_size, shared_decompressed AND_CAPTURE_MEMBER_FUNCTION_POINTERS ](pplx::task<size_t > op)
1490
1517
{
1491
1518
size_t writtenSize = 0 ;
1492
1519
try
@@ -1508,7 +1535,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
1508
1535
else
1509
1536
{
1510
1537
writeBuffer.putn_nocopy (boost::asio::buffer_cast<const uint8_t *>(m_body_buf.data ()), read_size)
1511
- .then ([this_request](pplx::task<size_t > op)
1538
+ .then ([this_request AND_CAPTURE_MEMBER_FUNCTION_POINTERS ](pplx::task<size_t > op)
1512
1539
{
1513
1540
size_t writtenSize = 0 ;
1514
1541
try
@@ -1559,7 +1586,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
1559
1586
1560
1587
m_timer.expires_from_now (m_duration);
1561
1588
auto ctx = m_ctx;
1562
- m_timer.async_wait ([ctx](const boost::system::error_code& ec)
1589
+ m_timer.async_wait ([ctx AND_CAPTURE_MEMBER_FUNCTION_POINTERS ](const boost::system::error_code& ec)
1563
1590
{
1564
1591
handle_timeout (ec, ctx);
1565
1592
});
@@ -1574,7 +1601,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
1574
1601
// The existing handler was canceled so schedule a new one.
1575
1602
assert (m_state == started);
1576
1603
auto ctx = m_ctx;
1577
- m_timer.async_wait ([ctx](const boost::system::error_code& ec)
1604
+ m_timer.async_wait ([ctx AND_CAPTURE_MEMBER_FUNCTION_POINTERS ](const boost::system::error_code& ec)
1578
1605
{
1579
1606
handle_timeout (ec, ctx);
1580
1607
});
0 commit comments