From ed94a6cddb46f2e216997b85bc6c1f04ffb510c6 Mon Sep 17 00:00:00 2001 From: Billy O'Neal Date: Mon, 8 Oct 2018 19:25:17 -0700 Subject: [PATCH] Fix build breaks on GCC 5.4, iOS, and OSX (#894) * Move up bind_impl so that it can be found by non-MSVC. * Avoid useless qualification making GCC unhappy. * Make GZIP/DEFLATE/BROTLI constant chars. * Remove unneeded ; * Remove broken qualification attempting to forward declare web::http::compression::decompress_factory. * Don't use nonstandard for each. * Remove another unnecessary const. * Mark unused parameters with (void). * Guard -Wno-format-truncation from GCC 5.4. * Fix bogus writtenSize warning from GCC 5.4. * Attempt to avoid std::make_unique in compression tests. * Avoid Concurrency::task_group_status because gcc 5.4 hates it for some reason. --- Release/CMakeLists.txt | 6 +- Release/include/cpprest/http_compression.h | 10 +-- Release/include/cpprest/http_headers.h | 62 +++++++++---------- Release/src/http/client/http_client_asio.cpp | 1 + Release/src/http/common/http_compression.cpp | 17 ++++- .../src/http/common/internal_http_helpers.h | 2 +- .../http/client/compression_tests.cpp | 45 +++++++------- 7 files changed, 80 insertions(+), 63 deletions(-) diff --git a/Release/CMakeLists.txt b/Release/CMakeLists.txt index 4a5bdef42..00fa7a7d1 100644 --- a/Release/CMakeLists.txt +++ b/Release/CMakeLists.txt @@ -187,7 +187,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR IOS) elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") message("-- Setting gcc options") - set(WARNINGS -Wall -Wextra -Wunused-parameter -Wcast-align -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls -Wunreachable-code -Wno-format-truncation) + set(WARNINGS -Wall -Wextra -Wunused-parameter -Wcast-align -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls -Wunreachable-code) + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0") + set(WARNINGS ${WARNINGS} -Wno-format-truncation) + endif() + set(LD_FLAGS "${LD_FLAGS} -Wl,-z,defs") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-strict-aliasing") diff --git a/Release/include/cpprest/http_compression.h b/Release/include/cpprest/http_compression.h index 13b183af0..1993e6244 100644 --- a/Release/include/cpprest/http_compression.h +++ b/Release/include/cpprest/http_compression.h @@ -96,7 +96,7 @@ class decompress_factory { public: virtual const utility::string_t& algorithm() const = 0; - virtual const uint16_t weight() const = 0; + virtual uint16_t weight() const = 0; virtual std::unique_ptr make_decompressor() const = 0; virtual ~decompress_factory() = default; }; @@ -117,9 +117,9 @@ _ASYNCRTIMP bool supported(); /// namespace algorithm { -constexpr utility::char_t *GZIP = _XPLATSTR("gzip"); -constexpr utility::char_t *DEFLATE = _XPLATSTR("deflate"); -constexpr utility::char_t *BROTLI = _XPLATSTR("br"); +constexpr const utility::char_t *GZIP = _XPLATSTR("gzip"); +constexpr const utility::char_t *DEFLATE = _XPLATSTR("deflate"); +constexpr const utility::char_t *BROTLI = _XPLATSTR("br"); /// /// Test whether cpprestsdk was built with built-in compression support and @@ -129,7 +129,7 @@ constexpr utility::char_t *BROTLI = _XPLATSTR("br"); /// the supplied string matches a supported built-in algorithm, and false if not. /// _ASYNCRTIMP bool supported(const utility::string_t& algorithm); -}; +} /// /// Factory function to instantiate a built-in compression provider with default parameters by compression algorithm diff --git a/Release/include/cpprest/http_headers.h b/Release/include/cpprest/http_headers.h index 077266a7d..3761940c8 100644 --- a/Release/include/cpprest/http_headers.h +++ b/Release/include/cpprest/http_headers.h @@ -57,6 +57,37 @@ bool bind(const key_type &text, utility::string_t &ref) //const return true; } +namespace details +{ + template + bool bind_impl(const key_type &text, _t &ref) + { + utility::istringstream_t iss(text); + iss.imbue(std::locale::classic()); + iss >> ref; + if (iss.fail() || !iss.eof()) + { + return false; + } + + return true; + } + + template + bool bind_impl(const key_type &text, utf16string &ref) + { + ref = utility::conversions::to_utf16string(text); + return true; + } + + template + bool bind_impl(const key_type &text, std::string &ref) + { + ref = utility::conversions::to_utf8string(text); + return true; + } +} + /// /// Represents HTTP headers, acts like a map. /// @@ -288,35 +319,4 @@ private: // Headers are stored in a map with case insensitive key. inner_container m_headers; }; - -namespace details -{ - template - bool bind_impl(const key_type &text, _t &ref) - { - utility::istringstream_t iss(text); - iss.imbue(std::locale::classic()); - iss >> ref; - if (iss.fail() || !iss.eof()) - { - return false; - } - - return true; - } - - template - bool bind_impl(const key_type &text, utf16string &ref) - { - ref = utility::conversions::to_utf16string(text); - return true; - } - - template - bool bind_impl(const key_type &text, std::string &ref) - { - ref = utility::conversions::to_utf8string(text); - return true; - } -} }} diff --git a/Release/src/http/client/http_client_asio.cpp b/Release/src/http/client/http_client_asio.cpp index 759049742..72e13f046 100644 --- a/Release/src/http/client/http_client_asio.cpp +++ b/Release/src/http/client/http_client_asio.cpp @@ -1754,6 +1754,7 @@ private: .then([this_request, read_size, shared_decompressed AND_CAPTURE_MEMBER_FUNCTION_POINTERS]( pplx::task op) { size_t writtenSize = 0; + (void)writtenSize; try { writtenSize = op.get(); diff --git a/Release/src/http/common/http_compression.cpp b/Release/src/http/common/http_compression.cpp index e7e7f9a92..7fc229642 100644 --- a/Release/src/http/common/http_compression.cpp +++ b/Release/src/http/common/http_compression.cpp @@ -620,7 +620,7 @@ public: const utility::string_t& algorithm() const { return m_algorithm; } - const uint16_t weight() const { return m_weight; } + uint16_t weight() const { return m_weight; } std::unique_ptr make_decompressor() const { return _make_decompressor(); } @@ -753,6 +753,10 @@ std::unique_ptr make_gzip_compressor(int compressionLevel, in #if defined(CPPREST_HTTP_COMPRESSION) return std::move(std::make_unique(compressionLevel, method, strategy, memLevel)); #else // CPPREST_HTTP_COMPRESSION + (void)compressionLevel; + (void)method; + (void)strategy; + (void)memLevel; return std::unique_ptr(); #endif // CPPREST_HTTP_COMPRESSION } @@ -762,6 +766,10 @@ std::unique_ptr make_deflate_compressor(int compressionLevel, #if defined(CPPREST_HTTP_COMPRESSION) return std::move(std::make_unique(compressionLevel, method, strategy, memLevel)); #else // CPPREST_HTTP_COMPRESSION + (void)compressionLevel; + (void)method; + (void)strategy; + (void)memLevel; return std::unique_ptr(); #endif // CPPREST_HTTP_COMPRESSION } @@ -771,6 +779,9 @@ std::unique_ptr make_brotli_compressor(uint32_t window, uint3 #if defined(CPPREST_HTTP_COMPRESSION) && defined(CPPREST_BROTLI_COMPRESSION) return std::move(std::make_unique(window, quality, mode)); #else // CPPREST_BROTLI_COMPRESSION + (void)window; + (void)quality; + (void)mode; return std::unique_ptr(); #endif // CPPREST_BROTLI_COMPRESSION } @@ -800,7 +811,7 @@ const std::vector> get_decompress_factories( } } // namespace builtin -static bool is_http_whitespace(utility::char_t ch) { return ch == _XPLATSTR(' ') || ch == _XPLATSTR('\t'); } +static bool is_http_whitespace(const utility::char_t ch) { return ch == _XPLATSTR(' ') || ch == _XPLATSTR('\t'); } static void remove_surrounding_http_whitespace(const utility::string_t& encoding, size_t& start, size_t& length) { @@ -1084,7 +1095,7 @@ utility::string_t build_supported_header(header_types type, // Add all specified algorithms and their weights to the header start = true; os.imbue(std::locale::classic()); - for each (auto& factory in f) + for (auto& factory : f) { if (factory) { diff --git a/Release/src/http/common/internal_http_helpers.h b/Release/src/http/common/internal_http_helpers.h index ef1961227..76b4f4f4d 100644 --- a/Release/src/http/common/internal_http_helpers.h +++ b/Release/src/http/common/internal_http_helpers.h @@ -34,7 +34,7 @@ bool validate_method(const utility::string_t& method); namespace web { namespace http { namespace compression { -class compression::decompress_factory; +class decompress_factory; namespace details { namespace builtin { diff --git a/Release/tests/functional/http/client/compression_tests.cpp b/Release/tests/functional/http/client/compression_tests.cpp index e9cc9ef66..ca2215afd 100644 --- a/Release/tests/functional/http/client/compression_tests.cpp +++ b/Release/tests/functional/http/client/compression_tests.cpp @@ -13,6 +13,7 @@ #include "cpprest/details/http_helpers.h" #include "cpprest/version.h" +#include "cpprest/asyncrt_utils.h" #include "stdafx.h" #include @@ -202,7 +203,7 @@ SUITE(compression_tests) std::vector dcmp_buffer; web::http::compression::operation_result r; std::vector chunk_sizes; - Concurrency::task_group_status result; + pplx::task_status result; size_t csize; size_t dsize; size_t i; @@ -210,8 +211,8 @@ SUITE(compression_tests) if (algorithm == fake_provider::FAKE) { - compressor = std::make_unique(buffer_size); - decompressor = std::make_unique(buffer_size); + compressor = utility::details::make_unique(buffer_size); + decompressor = utility::details::make_unique(buffer_size); } else { @@ -247,7 +248,7 @@ SUITE(compression_tests) web::http::compression::operation_hint::has_more) .then([&r](web::http::compression::operation_result x) { r = x; }) .wait(); - VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed); + VERIFY_ARE_EQUAL(result, pplx::task_status::completed); VERIFY_ARE_EQUAL(r.input_bytes_processed, std::min(chunk_size, buffer_size - i)); VERIFY_ARE_EQUAL(r.done, false); chunk_sizes.push_back(r.output_bytes_produced); @@ -272,7 +273,7 @@ SUITE(compression_tests) web::http::compression::operation_hint::is_last) .then([&r](web::http::compression::operation_result x) { r = x; }) .wait(); - VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed); + VERIFY_ARE_EQUAL(result, pplx::task_status::completed); VERIFY_ARE_EQUAL(r.input_bytes_processed, 0); chunk_sizes.push_back(r.output_bytes_produced); csize += r.output_bytes_produced; @@ -283,7 +284,7 @@ SUITE(compression_tests) result = compressor->compress(NULL, 0, NULL, 0, web::http::compression::operation_hint::is_last) .then([&r](web::http::compression::operation_result x) { r = x; }) .wait(); - VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed); + VERIFY_ARE_EQUAL(result, pplx::task_status::completed); VERIFY_ARE_EQUAL(r.input_bytes_processed, 0); VERIFY_ARE_EQUAL(r.output_bytes_produced, 0); VERIFY_ARE_EQUAL(r.done, true); @@ -311,7 +312,7 @@ SUITE(compression_tests) hint) .then([&r](web::http::compression::operation_result x) { r = x; }) .wait(); - VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed); + VERIFY_ARE_EQUAL(result, pplx::task_status::completed); nn += *it; dsize += r.output_bytes_produced; } @@ -339,7 +340,7 @@ SUITE(compression_tests) web::http::compression::operation_hint::has_more) .then([&r](web::http::compression::operation_result x) { r = x; }) .wait(); - VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed); + VERIFY_ARE_EQUAL(result, pplx::task_status::completed); dsize += r.output_bytes_produced; nn += r.input_bytes_processed; n -= r.input_bytes_processed; @@ -354,7 +355,7 @@ SUITE(compression_tests) result = decompressor->decompress(NULL, 0, NULL, 0, web::http::compression::operation_hint::has_more) .then([&r](web::http::compression::operation_result x) { r = x; }) .wait(); - VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed); + VERIFY_ARE_EQUAL(result, pplx::task_status::completed); VERIFY_ARE_EQUAL(r.input_bytes_processed, 0); VERIFY_ARE_EQUAL(r.output_bytes_produced, 0); VERIFY_IS_TRUE(r.done); @@ -370,7 +371,7 @@ SUITE(compression_tests) web::http::compression::operation_hint::is_last) .then([&r](web::http::compression::operation_result x) { r = x; }) .wait(); - VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed); + VERIFY_ARE_EQUAL(result, pplx::task_status::completed); VERIFY_ARE_EQUAL(r.output_bytes_produced, buffer_size); VERIFY_ARE_EQUAL(input_buffer, dcmp_buffer); @@ -448,28 +449,28 @@ SUITE(compression_tests) std::shared_ptr fcf = web::http::compression::make_compress_factory( fake_provider::FAKE, []() -> std::unique_ptr { - return std::make_unique(); + return utility::details::make_unique(); }); std::vector> fcv; fcv.push_back(fcf); std::shared_ptr fdf = web::http::compression::make_decompress_factory( fake_provider::FAKE, 800, []() -> std::unique_ptr { - return std::make_unique(); + return utility::details::make_unique(); }); std::vector> fdv; fdv.push_back(fdf); std::shared_ptr ncf = web::http::compression::make_compress_factory( _NONE, []() -> std::unique_ptr { - return std::make_unique(); + return utility::details::make_unique(); }); std::vector> ncv; ncv.push_back(ncf); std::shared_ptr ndf = web::http::compression::make_decompress_factory( _NONE, 800, []() -> std::unique_ptr { - return std::make_unique(); + return utility::details::make_unique(); }); std::vector> ndv; ndv.push_back(ndf); @@ -794,7 +795,7 @@ SUITE(compression_tests) { test_http_server* p_server = nullptr; std::unique_ptr scoped = - std::move(std::make_unique(m_uri)); + std::move(utility::details::make_unique(m_uri)); scoped->server()->next_request().then([&skip_transfer_put](pplx::task op) { try { @@ -810,7 +811,7 @@ SUITE(compression_tests) http_client client(m_uri); http_request msg(methods::PUT); - msg.set_compressor(std::make_unique(0)); + msg.set_compressor(utility::details::make_unique(0)); msg.set_body(concurrency::streams::rawptr_stream::open_istream((const uint8_t*)nullptr, 0)); http_response rsp = client.request(msg).get(); rsp.content_ready().wait(); @@ -872,7 +873,7 @@ SUITE(compression_tests) if (encoding.find(fake_provider::FAKE) != utility::string_t::npos) { // This one won't be found in the server's default set... - rsp._get_impl()->set_compressor(std::make_unique(buffer_size)); + rsp._get_impl()->set_compressor(utility::details::make_unique(buffer_size)); } #endif // _WIN32 rsp.set_body( @@ -913,7 +914,7 @@ SUITE(compression_tests) } else { - scoped = std::move(std::make_unique(m_uri)); + scoped = std::move(utility::details::make_unique(m_uri)); p_server = scoped->server(); } @@ -968,12 +969,12 @@ SUITE(compression_tests) fake_provider::FAKE, 1000, [buffer_size]() -> std::unique_ptr { - return std::make_unique(buffer_size); + return utility::details::make_unique(buffer_size); }); dfactories.push_back(dmap[fake_provider::FAKE]); cfactories.push_back(web::http::compression::make_compress_factory( fake_provider::FAKE, [buffer_size]() -> std::unique_ptr { - return std::make_unique(buffer_size); + return utility::details::make_unique(buffer_size); })); v.resize(buffer_size); @@ -1037,7 +1038,7 @@ SUITE(compression_tests) if (algorithm == fake_provider::FAKE) { VERIFY_IS_FALSE((bool)c); - c = std::make_unique(buffer_size); + c = utility::details::make_unique(buffer_size); } VERIFY_IS_TRUE((bool)c); auto got = c->compress(v.data(), @@ -1069,7 +1070,7 @@ SUITE(compression_tests) VERIFY_ARE_EQUAL(boo, algorithm != fake_provider::FAKE); if (algorithm == fake_provider::FAKE) { - msg.set_compressor(std::make_unique(buffer_size)); + msg.set_compressor(utility::details::make_unique(buffer_size)); } } else