Skip to content

Commit ed94a6c

Browse files
authored
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.
1 parent 74da372 commit ed94a6c

File tree

7 files changed

+80
-63
lines changed

7 files changed

+80
-63
lines changed

Release/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR IOS)
187187
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
188188
message("-- Setting gcc options")
189189

190-
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)
190+
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)
191+
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0")
192+
set(WARNINGS ${WARNINGS} -Wno-format-truncation)
193+
endif()
194+
191195
set(LD_FLAGS "${LD_FLAGS} -Wl,-z,defs")
192196

193197
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-strict-aliasing")

Release/include/cpprest/http_compression.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class decompress_factory
9696
{
9797
public:
9898
virtual const utility::string_t& algorithm() const = 0;
99-
virtual const uint16_t weight() const = 0;
99+
virtual uint16_t weight() const = 0;
100100
virtual std::unique_ptr<decompress_provider> make_decompressor() const = 0;
101101
virtual ~decompress_factory() = default;
102102
};
@@ -117,9 +117,9 @@ _ASYNCRTIMP bool supported();
117117
/// </summary>
118118
namespace algorithm
119119
{
120-
constexpr utility::char_t *GZIP = _XPLATSTR("gzip");
121-
constexpr utility::char_t *DEFLATE = _XPLATSTR("deflate");
122-
constexpr utility::char_t *BROTLI = _XPLATSTR("br");
120+
constexpr const utility::char_t *GZIP = _XPLATSTR("gzip");
121+
constexpr const utility::char_t *DEFLATE = _XPLATSTR("deflate");
122+
constexpr const utility::char_t *BROTLI = _XPLATSTR("br");
123123

124124
/// <summary>
125125
/// Test whether cpprestsdk was built with built-in compression support and
@@ -129,7 +129,7 @@ constexpr utility::char_t *BROTLI = _XPLATSTR("br");
129129
/// the supplied string matches a supported built-in algorithm, and false if not.</returns>
130130
/// <summary>
131131
_ASYNCRTIMP bool supported(const utility::string_t& algorithm);
132-
};
132+
}
133133

134134
/// <summary>
135135
/// Factory function to instantiate a built-in compression provider with default parameters by compression algorithm

Release/include/cpprest/http_headers.h

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,37 @@ bool bind(const key_type &text, utility::string_t &ref) //const
5757
return true;
5858
}
5959

60+
namespace details
61+
{
62+
template<typename key_type, typename _t>
63+
bool bind_impl(const key_type &text, _t &ref)
64+
{
65+
utility::istringstream_t iss(text);
66+
iss.imbue(std::locale::classic());
67+
iss >> ref;
68+
if (iss.fail() || !iss.eof())
69+
{
70+
return false;
71+
}
72+
73+
return true;
74+
}
75+
76+
template<typename key_type>
77+
bool bind_impl(const key_type &text, utf16string &ref)
78+
{
79+
ref = utility::conversions::to_utf16string(text);
80+
return true;
81+
}
82+
83+
template<typename key_type>
84+
bool bind_impl(const key_type &text, std::string &ref)
85+
{
86+
ref = utility::conversions::to_utf8string(text);
87+
return true;
88+
}
89+
}
90+
6091
/// <summary>
6192
/// Represents HTTP headers, acts like a map.
6293
/// </summary>
@@ -288,35 +319,4 @@ class http_headers
288319
// Headers are stored in a map with case insensitive key.
289320
inner_container m_headers;
290321
};
291-
292-
namespace details
293-
{
294-
template<typename key_type, typename _t>
295-
bool bind_impl(const key_type &text, _t &ref)
296-
{
297-
utility::istringstream_t iss(text);
298-
iss.imbue(std::locale::classic());
299-
iss >> ref;
300-
if (iss.fail() || !iss.eof())
301-
{
302-
return false;
303-
}
304-
305-
return true;
306-
}
307-
308-
template<typename key_type>
309-
bool bind_impl(const key_type &text, utf16string &ref)
310-
{
311-
ref = utility::conversions::to_utf16string(text);
312-
return true;
313-
}
314-
315-
template<typename key_type>
316-
bool bind_impl(const key_type &text, std::string &ref)
317-
{
318-
ref = utility::conversions::to_utf8string(text);
319-
return true;
320-
}
321-
}
322322
}}

Release/src/http/client/http_client_asio.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,7 @@ class asio_context final : public request_context, public std::enable_shared_fro
17541754
.then([this_request, read_size, shared_decompressed AND_CAPTURE_MEMBER_FUNCTION_POINTERS](
17551755
pplx::task<size_t> op) {
17561756
size_t writtenSize = 0;
1757+
(void)writtenSize;
17571758
try
17581759
{
17591760
writtenSize = op.get();

Release/src/http/common/http_compression.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ class generic_decompress_factory : public decompress_factory
620620

621621
const utility::string_t& algorithm() const { return m_algorithm; }
622622

623-
const uint16_t weight() const { return m_weight; }
623+
uint16_t weight() const { return m_weight; }
624624

625625
std::unique_ptr<decompress_provider> make_decompressor() const { return _make_decompressor(); }
626626

@@ -753,6 +753,10 @@ std::unique_ptr<compress_provider> make_gzip_compressor(int compressionLevel, in
753753
#if defined(CPPREST_HTTP_COMPRESSION)
754754
return std::move(std::make_unique<gzip_compressor>(compressionLevel, method, strategy, memLevel));
755755
#else // CPPREST_HTTP_COMPRESSION
756+
(void)compressionLevel;
757+
(void)method;
758+
(void)strategy;
759+
(void)memLevel;
756760
return std::unique_ptr<compress_provider>();
757761
#endif // CPPREST_HTTP_COMPRESSION
758762
}
@@ -762,6 +766,10 @@ std::unique_ptr<compress_provider> make_deflate_compressor(int compressionLevel,
762766
#if defined(CPPREST_HTTP_COMPRESSION)
763767
return std::move(std::make_unique<deflate_compressor>(compressionLevel, method, strategy, memLevel));
764768
#else // CPPREST_HTTP_COMPRESSION
769+
(void)compressionLevel;
770+
(void)method;
771+
(void)strategy;
772+
(void)memLevel;
765773
return std::unique_ptr<compress_provider>();
766774
#endif // CPPREST_HTTP_COMPRESSION
767775
}
@@ -771,6 +779,9 @@ std::unique_ptr<compress_provider> make_brotli_compressor(uint32_t window, uint3
771779
#if defined(CPPREST_HTTP_COMPRESSION) && defined(CPPREST_BROTLI_COMPRESSION)
772780
return std::move(std::make_unique<brotli_compressor>(window, quality, mode));
773781
#else // CPPREST_BROTLI_COMPRESSION
782+
(void)window;
783+
(void)quality;
784+
(void)mode;
774785
return std::unique_ptr<compress_provider>();
775786
#endif // CPPREST_BROTLI_COMPRESSION
776787
}
@@ -800,7 +811,7 @@ const std::vector<std::shared_ptr<decompress_factory>> get_decompress_factories(
800811
}
801812
} // namespace builtin
802813

803-
static bool is_http_whitespace(utility::char_t ch) { return ch == _XPLATSTR(' ') || ch == _XPLATSTR('\t'); }
814+
static bool is_http_whitespace(const utility::char_t ch) { return ch == _XPLATSTR(' ') || ch == _XPLATSTR('\t'); }
804815

805816
static void remove_surrounding_http_whitespace(const utility::string_t& encoding, size_t& start, size_t& length)
806817
{
@@ -1084,7 +1095,7 @@ utility::string_t build_supported_header(header_types type,
10841095
// Add all specified algorithms and their weights to the header
10851096
start = true;
10861097
os.imbue(std::locale::classic());
1087-
for each (auto& factory in f)
1098+
for (auto& factory : f)
10881099
{
10891100
if (factory)
10901101
{

Release/src/http/common/internal_http_helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ bool validate_method(const utility::string_t& method);
3434

3535
namespace web { namespace http { namespace compression {
3636

37-
class compression::decompress_factory;
37+
class decompress_factory;
3838

3939
namespace details { namespace builtin {
4040

Release/tests/functional/http/client/compression_tests.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "cpprest/details/http_helpers.h"
1515
#include "cpprest/version.h"
16+
#include "cpprest/asyncrt_utils.h"
1617
#include "stdafx.h"
1718
#include <fstream>
1819

@@ -202,16 +203,16 @@ SUITE(compression_tests)
202203
std::vector<uint8_t> dcmp_buffer;
203204
web::http::compression::operation_result r;
204205
std::vector<size_t> chunk_sizes;
205-
Concurrency::task_group_status result;
206+
pplx::task_status result;
206207
size_t csize;
207208
size_t dsize;
208209
size_t i;
209210
size_t nn;
210211

211212
if (algorithm == fake_provider::FAKE)
212213
{
213-
compressor = std::make_unique<fake_provider>(buffer_size);
214-
decompressor = std::make_unique<fake_provider>(buffer_size);
214+
compressor = utility::details::make_unique<fake_provider>(buffer_size);
215+
decompressor = utility::details::make_unique<fake_provider>(buffer_size);
215216
}
216217
else
217218
{
@@ -247,7 +248,7 @@ SUITE(compression_tests)
247248
web::http::compression::operation_hint::has_more)
248249
.then([&r](web::http::compression::operation_result x) { r = x; })
249250
.wait();
250-
VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed);
251+
VERIFY_ARE_EQUAL(result, pplx::task_status::completed);
251252
VERIFY_ARE_EQUAL(r.input_bytes_processed, std::min(chunk_size, buffer_size - i));
252253
VERIFY_ARE_EQUAL(r.done, false);
253254
chunk_sizes.push_back(r.output_bytes_produced);
@@ -272,7 +273,7 @@ SUITE(compression_tests)
272273
web::http::compression::operation_hint::is_last)
273274
.then([&r](web::http::compression::operation_result x) { r = x; })
274275
.wait();
275-
VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed);
276+
VERIFY_ARE_EQUAL(result, pplx::task_status::completed);
276277
VERIFY_ARE_EQUAL(r.input_bytes_processed, 0);
277278
chunk_sizes.push_back(r.output_bytes_produced);
278279
csize += r.output_bytes_produced;
@@ -283,7 +284,7 @@ SUITE(compression_tests)
283284
result = compressor->compress(NULL, 0, NULL, 0, web::http::compression::operation_hint::is_last)
284285
.then([&r](web::http::compression::operation_result x) { r = x; })
285286
.wait();
286-
VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed);
287+
VERIFY_ARE_EQUAL(result, pplx::task_status::completed);
287288
VERIFY_ARE_EQUAL(r.input_bytes_processed, 0);
288289
VERIFY_ARE_EQUAL(r.output_bytes_produced, 0);
289290
VERIFY_ARE_EQUAL(r.done, true);
@@ -311,7 +312,7 @@ SUITE(compression_tests)
311312
hint)
312313
.then([&r](web::http::compression::operation_result x) { r = x; })
313314
.wait();
314-
VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed);
315+
VERIFY_ARE_EQUAL(result, pplx::task_status::completed);
315316
nn += *it;
316317
dsize += r.output_bytes_produced;
317318
}
@@ -339,7 +340,7 @@ SUITE(compression_tests)
339340
web::http::compression::operation_hint::has_more)
340341
.then([&r](web::http::compression::operation_result x) { r = x; })
341342
.wait();
342-
VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed);
343+
VERIFY_ARE_EQUAL(result, pplx::task_status::completed);
343344
dsize += r.output_bytes_produced;
344345
nn += r.input_bytes_processed;
345346
n -= r.input_bytes_processed;
@@ -354,7 +355,7 @@ SUITE(compression_tests)
354355
result = decompressor->decompress(NULL, 0, NULL, 0, web::http::compression::operation_hint::has_more)
355356
.then([&r](web::http::compression::operation_result x) { r = x; })
356357
.wait();
357-
VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed);
358+
VERIFY_ARE_EQUAL(result, pplx::task_status::completed);
358359
VERIFY_ARE_EQUAL(r.input_bytes_processed, 0);
359360
VERIFY_ARE_EQUAL(r.output_bytes_produced, 0);
360361
VERIFY_IS_TRUE(r.done);
@@ -370,7 +371,7 @@ SUITE(compression_tests)
370371
web::http::compression::operation_hint::is_last)
371372
.then([&r](web::http::compression::operation_result x) { r = x; })
372373
.wait();
373-
VERIFY_ARE_EQUAL(result, Concurrency::task_group_status::completed);
374+
VERIFY_ARE_EQUAL(result, pplx::task_status::completed);
374375
VERIFY_ARE_EQUAL(r.output_bytes_produced, buffer_size);
375376
VERIFY_ARE_EQUAL(input_buffer, dcmp_buffer);
376377

@@ -448,28 +449,28 @@ SUITE(compression_tests)
448449

449450
std::shared_ptr<web::http::compression::compress_factory> fcf = web::http::compression::make_compress_factory(
450451
fake_provider::FAKE, []() -> std::unique_ptr<web::http::compression::compress_provider> {
451-
return std::make_unique<fake_provider>();
452+
return utility::details::make_unique<fake_provider>();
452453
});
453454
std::vector<std::shared_ptr<web::http::compression::compress_factory>> fcv;
454455
fcv.push_back(fcf);
455456
std::shared_ptr<web::http::compression::decompress_factory> fdf =
456457
web::http::compression::make_decompress_factory(
457458
fake_provider::FAKE, 800, []() -> std::unique_ptr<web::http::compression::decompress_provider> {
458-
return std::make_unique<fake_provider>();
459+
return utility::details::make_unique<fake_provider>();
459460
});
460461
std::vector<std::shared_ptr<web::http::compression::decompress_factory>> fdv;
461462
fdv.push_back(fdf);
462463

463464
std::shared_ptr<web::http::compression::compress_factory> ncf = web::http::compression::make_compress_factory(
464465
_NONE, []() -> std::unique_ptr<web::http::compression::compress_provider> {
465-
return std::make_unique<fake_provider>();
466+
return utility::details::make_unique<fake_provider>();
466467
});
467468
std::vector<std::shared_ptr<web::http::compression::compress_factory>> ncv;
468469
ncv.push_back(ncf);
469470
std::shared_ptr<web::http::compression::decompress_factory> ndf =
470471
web::http::compression::make_decompress_factory(
471472
_NONE, 800, []() -> std::unique_ptr<web::http::compression::decompress_provider> {
472-
return std::make_unique<fake_provider>();
473+
return utility::details::make_unique<fake_provider>();
473474
});
474475
std::vector<std::shared_ptr<web::http::compression::decompress_factory>> ndv;
475476
ndv.push_back(ndf);
@@ -794,7 +795,7 @@ SUITE(compression_tests)
794795
{
795796
test_http_server* p_server = nullptr;
796797
std::unique_ptr<test_http_server::scoped_server> scoped =
797-
std::move(std::make_unique<test_http_server::scoped_server>(m_uri));
798+
std::move(utility::details::make_unique<test_http_server::scoped_server>(m_uri));
798799
scoped->server()->next_request().then([&skip_transfer_put](pplx::task<test_request*> op) {
799800
try
800801
{
@@ -810,7 +811,7 @@ SUITE(compression_tests)
810811

811812
http_client client(m_uri);
812813
http_request msg(methods::PUT);
813-
msg.set_compressor(std::make_unique<fake_provider>(0));
814+
msg.set_compressor(utility::details::make_unique<fake_provider>(0));
814815
msg.set_body(concurrency::streams::rawptr_stream<uint8_t>::open_istream((const uint8_t*)nullptr, 0));
815816
http_response rsp = client.request(msg).get();
816817
rsp.content_ready().wait();
@@ -872,7 +873,7 @@ SUITE(compression_tests)
872873
if (encoding.find(fake_provider::FAKE) != utility::string_t::npos)
873874
{
874875
// This one won't be found in the server's default set...
875-
rsp._get_impl()->set_compressor(std::make_unique<fake_provider>(buffer_size));
876+
rsp._get_impl()->set_compressor(utility::details::make_unique<fake_provider>(buffer_size));
876877
}
877878
#endif // _WIN32
878879
rsp.set_body(
@@ -913,7 +914,7 @@ SUITE(compression_tests)
913914
}
914915
else
915916
{
916-
scoped = std::move(std::make_unique<test_http_server::scoped_server>(m_uri));
917+
scoped = std::move(utility::details::make_unique<test_http_server::scoped_server>(m_uri));
917918
p_server = scoped->server();
918919
}
919920

@@ -968,12 +969,12 @@ SUITE(compression_tests)
968969
fake_provider::FAKE,
969970
1000,
970971
[buffer_size]() -> std::unique_ptr<web::http::compression::decompress_provider> {
971-
return std::make_unique<fake_provider>(buffer_size);
972+
return utility::details::make_unique<fake_provider>(buffer_size);
972973
});
973974
dfactories.push_back(dmap[fake_provider::FAKE]);
974975
cfactories.push_back(web::http::compression::make_compress_factory(
975976
fake_provider::FAKE, [buffer_size]() -> std::unique_ptr<web::http::compression::compress_provider> {
976-
return std::make_unique<fake_provider>(buffer_size);
977+
return utility::details::make_unique<fake_provider>(buffer_size);
977978
}));
978979

979980
v.resize(buffer_size);
@@ -1037,7 +1038,7 @@ SUITE(compression_tests)
10371038
if (algorithm == fake_provider::FAKE)
10381039
{
10391040
VERIFY_IS_FALSE((bool)c);
1040-
c = std::make_unique<fake_provider>(buffer_size);
1041+
c = utility::details::make_unique<fake_provider>(buffer_size);
10411042
}
10421043
VERIFY_IS_TRUE((bool)c);
10431044
auto got = c->compress(v.data(),
@@ -1069,7 +1070,7 @@ SUITE(compression_tests)
10691070
VERIFY_ARE_EQUAL(boo, algorithm != fake_provider::FAKE);
10701071
if (algorithm == fake_provider::FAKE)
10711072
{
1072-
msg.set_compressor(std::make_unique<fake_provider>(buffer_size));
1073+
msg.set_compressor(utility::details::make_unique<fake_provider>(buffer_size));
10731074
}
10741075
}
10751076
else

0 commit comments

Comments
 (0)