Skip to content

Commit 50e81a5

Browse files
authored
Merge pull request #609 from garethsb-sony/gcc-4.7
Support for GCC 4.7 (and VS2013)
2 parents b8d1c06 + d0ce63e commit 50e81a5

File tree

5 files changed

+47
-15
lines changed

5 files changed

+47
-15
lines changed

Release/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
188188
set(LD_FLAGS "${LD_FLAGS} -Wl,-z,defs")
189189

190190
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-strict-aliasing")
191+
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
192+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -D_GLIBCXX_USE_SCHED_YIELD -D_GLIBCXX_USE_NANOSLEEP")
193+
endif()
191194

192195
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
193196
message("-- Setting msvc options")

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__
@@ -621,7 +648,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
621648
proxy_host = utility::conversions::to_utf8string(proxy_uri.host());
622649
}
623650

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)
625652
{
626653
if (ctx->m_request._cancellation_token().is_canceled())
627654
{
@@ -1011,7 +1038,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
10111038
auto readbuf = _get_readbuffer();
10121039
uint8_t *buf = boost::asio::buffer_cast<uint8_t *>(m_body_buf.prepare(chunkSize + http::details::chunked_encoding::additional_encoding_space));
10131040
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)
10151042
{
10161043
size_t readSize = 0;
10171044
try
@@ -1068,7 +1095,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
10681095
const auto this_request = shared_from_this();
10691096
const auto readSize = static_cast<size_t>(std::min(static_cast<uint64_t>(m_http_client->client_config().chunksize()), m_content_length - m_uploaded));
10701097
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)
10721099
{
10731100
try
10741101
{
@@ -1371,7 +1398,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
13711398
auto shared_decompressed = std::make_shared<data_buffer>(std::move(decompressed));
13721399

13731400
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)
13751402
{
13761403
try
13771404
{
@@ -1389,7 +1416,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
13891416
}
13901417
else
13911418
{
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)
13931420
{
13941421
try
13951422
{
@@ -1486,7 +1513,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
14861513
auto shared_decompressed = std::make_shared<data_buffer>(std::move(decompressed));
14871514

14881515
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)
14901517
{
14911518
size_t writtenSize = 0;
14921519
try
@@ -1508,7 +1535,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
15081535
else
15091536
{
15101537
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)
15121539
{
15131540
size_t writtenSize = 0;
15141541
try
@@ -1559,7 +1586,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
15591586

15601587
m_timer.expires_from_now(m_duration);
15611588
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)
15631590
{
15641591
handle_timeout(ec, ctx);
15651592
});
@@ -1574,7 +1601,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
15741601
// The existing handler was canceled so schedule a new one.
15751602
assert(m_state == started);
15761603
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)
15781605
{
15791606
handle_timeout(ec, ctx);
15801607
});

Release/src/websockets/client/ws_client_wspp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class wspp_callback_client : public websocket_client_callback_impl, public std::
131131
#endif
132132
{}
133133

134-
~wspp_callback_client()
134+
~wspp_callback_client() CPPREST_NOEXCEPT
135135
{
136136
_ASSERTE(m_state < DESTROYED);
137137
std::unique_lock<std::mutex> lock(m_wspp_client_lock);
@@ -734,6 +734,7 @@ class wspp_callback_client : public websocket_client_callback_impl, public std::
734734
};
735735
struct websocketpp_client : websocketpp_client_base
736736
{
737+
~websocketpp_client() CPPREST_NOEXCEPT {}
737738
websocketpp::client<websocketpp::config::asio_client> & non_tls_client() override
738739
{
739740
return m_client;
@@ -743,6 +744,7 @@ class wspp_callback_client : public websocket_client_callback_impl, public std::
743744
};
744745
struct websocketpp_tls_client : websocketpp_client_base
745746
{
747+
~websocketpp_tls_client() CPPREST_NOEXCEPT {}
746748
websocketpp::client<websocketpp::config::asio_tls_client> & tls_client() override
747749
{
748750
return m_client;

Release/tests/common/TestRunner/test_runner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ testlist_t load_all_tests(test_module_loader& module_loader)
409409
testlist_t testlists;
410410

411411
// Retrieve the static tests and clear for dll loading.
412-
testlists.emplace("<static>", UnitTest::GetTestList());
412+
testlists.insert({ "<static>", UnitTest::GetTestList() });
413413
UnitTest::GetTestList().Clear();
414414

415415
// Cycle through all the test binaries and load them
@@ -445,7 +445,7 @@ testlist_t load_all_tests(test_module_loader& module_loader)
445445
std::cout << "Loaded " << binary << "..." << std::endl;
446446

447447
// Store the loaded binary into the test list map
448-
testlists.emplace(binary, UnitTest::GetTestList());
448+
testlists.insert({ binary, UnitTest::GetTestList() });
449449
UnitTest::GetTestList().Clear();
450450
}
451451
}

Release/tests/functional/json/parsing_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ TEST(escaping_control_characters)
223223

224224
for (int i : chars)
225225
{
226-
::utility::stringstream_t ss;
226+
utility::stringstream_t ss;
227227
ss << U("\"\\u") << std::uppercase << std::setfill(U('0')) << std::setw(4) << std::hex << i << U("\"");
228228
const auto &str = ss.str();
229229
auto expectedStr = str;
@@ -257,8 +257,8 @@ TEST(escaping_control_characters)
257257
}
258258

259259
// Try constructing a json string value directly.
260-
::utility::string_t schar;
261-
schar.push_back(static_cast<::utility::string_t::value_type>(i));
260+
utility::string_t schar;
261+
schar.push_back(static_cast<utility::string_t::value_type>(i));
262262
const auto &sv = json::value::string(schar);
263263
VERIFY_ARE_EQUAL(expectedStr, sv.serialize());
264264

0 commit comments

Comments
 (0)