From 17267ed4753655d78823f9d9f2eec3a9251de0d5 Mon Sep 17 00:00:00 2001 From: Takatoshi Kondo Date: Wed, 20 Mar 2019 17:35:00 +0900 Subject: [PATCH] Added -Wconversion support for C++. --- erb/v1/cpp03_zone.hpp.erb | 6 +-- include/msgpack/pack_template.h | 18 +++---- include/msgpack/sysdep.h | 10 ++-- .../v1/adaptor/check_container_size.hpp | 2 +- include/msgpack/v1/adaptor/cpp11/chrono.hpp | 10 ++-- include/msgpack/v1/adaptor/ext.hpp | 2 +- include/msgpack/v1/adaptor/fixint.hpp | 9 ++-- include/msgpack/v1/adaptor/int.hpp | 12 ++--- include/msgpack/v1/detail/cpp03_zone.hpp | 6 +-- include/msgpack/v1/detail/cpp11_zone.hpp | 6 +-- include/msgpack/v1/object.hpp | 4 +- include/msgpack/v1/object_fwd.hpp | 2 +- include/msgpack/v1/pack.hpp | 37 +++++++++++-- include/msgpack/v1/unpack.hpp | 22 ++++---- include/msgpack/v1/vrefbuffer.hpp | 14 ++--- include/msgpack/v1/zbuffer.hpp | 10 ++-- include/msgpack/v2/create_object_visitor.hpp | 2 +- include/msgpack/v2/parse.hpp | 26 ++++----- include/msgpack/v2/x3_parse.hpp | 54 ++++++++++--------- include/msgpack/v3/parse.hpp | 26 ++++----- include/msgpack/zbuffer.h | 12 ++--- include/msgpack/zone.h | 2 +- test/CMakeLists.txt | 2 +- test/array_ref.cpp | 5 ++ test/boost_fusion.cpp | 5 ++ test/boost_optional.cpp | 7 +++ test/boost_string_ref.cpp | 7 +++ test/boost_string_view.cpp | 6 +++ test/boost_variant.cpp | 24 +++++---- test/buffer.cpp | 7 +++ test/carray.cpp | 7 +++ test/cases.cpp | 8 ++- test/convert.cpp | 6 +++ test/fixint.cpp | 8 ++- test/fixint_c.cpp | 7 ++- test/fuzz_unpack_pack_fuzzer_cpp11.cpp | 5 ++ test/iterator_cpp11.cpp | 6 +++ test/json.cpp | 6 +++ test/limit.cpp | 7 +++ test/msgpack_basic.cpp | 17 +++--- test/msgpack_c.cpp | 9 +++- test/msgpack_container.cpp | 11 ++-- test/msgpack_cpp11.cpp | 5 ++ test/msgpack_cpp17.cpp | 5 ++ test/msgpack_stream.cpp | 11 ++-- test/msgpack_tuple.cpp | 6 +++ test/msgpack_vref.cpp | 5 ++ test/msgpack_x3_parse.cpp | 41 +++++++------- test/object.cpp | 6 +++ test/object_with_zone.cpp | 27 ++++++---- test/pack_unpack.cpp | 43 ++++++++------- test/pack_unpack_c.cpp | 7 +++ test/raw.cpp | 29 +++++----- test/reference.cpp | 6 +++ test/reference_cpp11.cpp | 6 +++ test/reference_wrapper_cpp11.cpp | 6 +++ test/shared_ptr_cpp11.cpp | 6 +++ test/size_equal_only.cpp | 6 +++ test/streaming.cpp | 13 +++-- test/streaming_c.cpp | 7 +++ test/unique_ptr_cpp11.cpp | 6 +++ test/user_class.cpp | 5 ++ test/version.cpp | 6 +++ test/visitor.cpp | 7 +++ test/zone.cpp | 6 +++ 65 files changed, 498 insertions(+), 219 deletions(-) diff --git a/erb/v1/cpp03_zone.hpp.erb b/erb/v1/cpp03_zone.hpp.erb index 78f60913..7dfc35c0 100644 --- a/erb/v1/cpp03_zone.hpp.erb +++ b/erb/v1/cpp03_zone.hpp.erb @@ -55,7 +55,7 @@ class zone { ++m_tail; } void push_expand(void (*func)(void*), void* data) { - const size_t nused = m_end - m_array; + const size_t nused = static_cast(m_end - m_array); size_t nnext; if(nused == 0) { nnext = (sizeof(finalizer) < 72/2) ? @@ -201,12 +201,12 @@ inline char* zone::get_aligned(char* ptr, size_t align) inline void* zone::allocate_align(size_t size, size_t align) { char* aligned = get_aligned(m_chunk_list.m_ptr, align); - size_t adjusted_size = size + (aligned - m_chunk_list.m_ptr); + size_t adjusted_size = size + static_cast(aligned - m_chunk_list.m_ptr); if (m_chunk_list.m_free < adjusted_size) { size_t enough_size = size + align - 1; char* ptr = allocate_expand(enough_size); aligned = get_aligned(ptr, align); - adjusted_size = size + (aligned - m_chunk_list.m_ptr); + adjusted_size = size + static_cast(aligned - m_chunk_list.m_ptr); } m_chunk_list.m_free -= adjusted_size; m_chunk_list.m_ptr += adjusted_size; diff --git a/include/msgpack/pack_template.h b/include/msgpack/pack_template.h index c534076d..ac112e1d 100644 --- a/include/msgpack/pack_template.h +++ b/include/msgpack/pack_template.h @@ -838,31 +838,31 @@ msgpack_pack_inline_func(_ext)(msgpack_pack_user x, size_t l, int8_t type) case 1: { unsigned char buf[2]; buf[0] = 0xd4; - buf[1] = type; + buf[1] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 2); } break; case 2: { unsigned char buf[2]; buf[0] = 0xd5; - buf[1] = type; + buf[1] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 2); } break; case 4: { unsigned char buf[2]; buf[0] = 0xd6; - buf[1] = type; + buf[1] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 2); } break; case 8: { unsigned char buf[2]; buf[0] = 0xd7; - buf[1] = type; + buf[1] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 2); } break; case 16: { unsigned char buf[2]; buf[0] = 0xd8; - buf[1] = type; + buf[1] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 2); } break; default: @@ -870,19 +870,19 @@ msgpack_pack_inline_func(_ext)(msgpack_pack_user x, size_t l, int8_t type) unsigned char buf[3]; buf[0] = 0xc7; buf[1] = (unsigned char)l; - buf[2] = type; + buf[2] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 3); } else if(l < 65536) { unsigned char buf[4]; buf[0] = 0xc8; _msgpack_store16(&buf[1], l); - buf[3] = type; + buf[3] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 4); } else { unsigned char buf[6]; buf[0] = 0xc9; _msgpack_store32(&buf[1], l); - buf[5] = type; + buf[5] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 6); } break; @@ -897,7 +897,7 @@ msgpack_pack_inline_func(_ext_body)(msgpack_pack_user x, const void* b, size_t l msgpack_pack_inline_func(_timestamp)(msgpack_pack_user x, const msgpack_timestamp* d) { if ((((int64_t)d->tv_sec) >> 34) == 0) { - uint64_t data64 = ((uint64_t) d->tv_nsec << 34) | d->tv_sec; + uint64_t data64 = ((uint64_t) d->tv_nsec << 34) | (uint64_t)d->tv_sec; if ((data64 & 0xffffffff00000000L) == 0) { // timestamp 32 char buf[4]; diff --git a/include/msgpack/sysdep.h b/include/msgpack/sysdep.h index e5a69fdb..99bbe1a0 100644 --- a/include/msgpack/sysdep.h +++ b/include/msgpack/sysdep.h @@ -95,7 +95,7 @@ #if MSGPACK_ENDIAN_LITTLE_BYTE # if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__) -# define _msgpack_be16(x) ntohs(x) +# define _msgpack_be16(x) ntohs((uint16_t)x) # else # if defined(ntohs) # define _msgpack_be16(x) ntohs(x) @@ -109,7 +109,7 @@ # endif # if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__) -# define _msgpack_be32(x) ntohl(x) +# define _msgpack_be32(x) ntohl((uint32_t)x) # else # if defined(ntohl) # define _msgpack_be32(x) ntohl(x) @@ -154,16 +154,16 @@ #define _msgpack_load16(cast, from, to) do { \ memcpy((cast*)(to), (from), sizeof(cast)); \ - *(to) = _msgpack_be16(*(to)); \ + *(to) = (cast)_msgpack_be16(*(to)); \ } while (0); #define _msgpack_load32(cast, from, to) do { \ memcpy((cast*)(to), (from), sizeof(cast)); \ - *(to) = _msgpack_be32(*(to)); \ + *(to) = (cast)_msgpack_be32(*(to)); \ } while (0); #define _msgpack_load64(cast, from, to) do { \ memcpy((cast*)(to), (from), sizeof(cast)); \ - *(to) = _msgpack_be64(*(to)); \ + *(to) = (cast)_msgpack_be64(*(to)); \ } while (0); #define _msgpack_store16(to, num) \ diff --git a/include/msgpack/v1/adaptor/check_container_size.hpp b/include/msgpack/v1/adaptor/check_container_size.hpp index 3f8409ab..8c4f23ce 100644 --- a/include/msgpack/v1/adaptor/check_container_size.hpp +++ b/include/msgpack/v1/adaptor/check_container_size.hpp @@ -53,7 +53,7 @@ inline void check_container_size_for_ext<4>(std::size_t size) { template inline uint32_t checked_get_container_size(T size) { - detail::check_container_size(size); + detail::check_container_size(static_cast(size)); return static_cast(size); } diff --git a/include/msgpack/v1/adaptor/cpp11/chrono.hpp b/include/msgpack/v1/adaptor/cpp11/chrono.hpp index db2035b7..bc5ca0b0 100644 --- a/include/msgpack/v1/adaptor/cpp11/chrono.hpp +++ b/include/msgpack/v1/adaptor/cpp11/chrono.hpp @@ -122,7 +122,7 @@ struct pack { * std::chrono::system_clock::duration::period::ratio::num / std::chrono::system_clock::duration::period::ratio::den; if ((sec >> 34) == 0) { - uint64_t data64 = (nanosec << 34) | sec; + uint64_t data64 = (static_cast(nanosec) << 34) | static_cast(sec); if ((data64 & 0xffffffff00000000L) == 0) { // timestamp 32 o.pack_ext(4, -1); @@ -170,13 +170,13 @@ struct object_with_zone { * std::chrono::system_clock::duration::period::ratio::num / std::chrono::system_clock::duration::period::ratio::den; if ((sec >> 34) == 0) { - uint64_t data64 = (nanosec << 34) | sec; + uint64_t data64 = (static_cast(nanosec) << 34) | static_cast(sec); if ((data64 & 0xffffffff00000000L) == 0) { // timestamp 32 o.type = msgpack::type::EXT; o.via.ext.size = 4; char* p = static_cast(o.zone.allocate_no_align(o.via.ext.size + 1)); - p[0] = -1; + p[0] = static_cast(-1); uint32_t data32 = static_cast(data64); _msgpack_store32(&p[1], data32); o.via.ext.ptr = p; @@ -186,7 +186,7 @@ struct object_with_zone { o.type = msgpack::type::EXT; o.via.ext.size = 8; char* p = static_cast(o.zone.allocate_no_align(o.via.ext.size + 1)); - p[0] = -1; + p[0] = static_cast(-1); _msgpack_store64(&p[1], data64); o.via.ext.ptr = p; } @@ -196,7 +196,7 @@ struct object_with_zone { o.type = msgpack::type::EXT; o.via.ext.size = 12; char* p = static_cast(o.zone.allocate_no_align(o.via.ext.size + 1)); - p[0] = -1; + p[0] = static_cast(-1); _msgpack_store32(&p[1], static_cast(nanosec)); _msgpack_store64(&p[1 + 4], sec); o.via.ext.ptr = p; diff --git a/include/msgpack/v1/adaptor/ext.hpp b/include/msgpack/v1/adaptor/ext.hpp index de375975..421b460c 100644 --- a/include/msgpack/v1/adaptor/ext.hpp +++ b/include/msgpack/v1/adaptor/ext.hpp @@ -178,7 +178,7 @@ inline ext::ext(ext_ref const& x) { // size limit has already been checked at ext_ref's constructor m_data.reserve(x.size() + 1); - m_data.push_back(x.type()); + m_data.push_back(static_cast(x.type())); m_data.insert(m_data.end(), x.data(), x.data() + x.size()); } diff --git a/include/msgpack/v1/adaptor/fixint.hpp b/include/msgpack/v1/adaptor/fixint.hpp index 7361edf9..360519c4 100644 --- a/include/msgpack/v1/adaptor/fixint.hpp +++ b/include/msgpack/v1/adaptor/fixint.hpp @@ -22,6 +22,7 @@ namespace type { template struct fix_int { + typedef T value_type; fix_int() : value(0) { } fix_int(T value) : value(value) { } @@ -152,7 +153,7 @@ struct object { } else { o.type = msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v.get(); + o.via.u64 = static_cast(v.get()); } } }; @@ -166,7 +167,7 @@ struct object { } else { o.type = msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v.get(); + o.via.u64 = static_cast(v.get()); } } }; @@ -180,7 +181,7 @@ struct object { } else { o.type = msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v.get(); + o.via.u64 = static_cast(v.get()); } } }; @@ -194,7 +195,7 @@ struct object { } else { o.type = msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v.get(); + o.via.u64 = static_cast(v.get()); } } }; diff --git a/include/msgpack/v1/adaptor/int.hpp b/include/msgpack/v1/adaptor/int.hpp index 4d6e83ae..11e73b0a 100644 --- a/include/msgpack/v1/adaptor/int.hpp +++ b/include/msgpack/v1/adaptor/int.hpp @@ -73,7 +73,7 @@ struct object_sign { } else { o.type = msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v; + o.via.u64 = static_cast(v); } } }; @@ -278,7 +278,7 @@ struct object { } else { o.type = msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v; + o.via.u64 = static_cast(v); } } }; @@ -292,7 +292,7 @@ struct object { } else { o.type = msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v; + o.via.u64 = static_cast(v); } } }; @@ -306,7 +306,7 @@ struct object { } else { o.type = msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v; + o.via.u64 = static_cast(v); } } }; @@ -320,7 +320,7 @@ struct object { } else { o.type = msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v; + o.via.u64 = static_cast(v); } } }; @@ -334,7 +334,7 @@ struct object { } else{ o.type = msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v; + o.via.u64 = static_cast(v); } } }; diff --git a/include/msgpack/v1/detail/cpp03_zone.hpp b/include/msgpack/v1/detail/cpp03_zone.hpp index 73abe694..21b3c5e8 100644 --- a/include/msgpack/v1/detail/cpp03_zone.hpp +++ b/include/msgpack/v1/detail/cpp03_zone.hpp @@ -55,7 +55,7 @@ class zone { ++m_tail; } void push_expand(void (*func)(void*), void* data) { - const size_t nused = m_end - m_array; + const size_t nused = static_cast(m_end - m_array); size_t nnext; if(nused == 0) { nnext = (sizeof(finalizer) < 72/2) ? @@ -246,12 +246,12 @@ inline char* zone::get_aligned(char* ptr, size_t align) inline void* zone::allocate_align(size_t size, size_t align) { char* aligned = get_aligned(m_chunk_list.m_ptr, align); - size_t adjusted_size = size + (aligned - m_chunk_list.m_ptr); + size_t adjusted_size = size + static_cast(aligned - m_chunk_list.m_ptr); if (m_chunk_list.m_free < adjusted_size) { size_t enough_size = size + align - 1; char* ptr = allocate_expand(enough_size); aligned = get_aligned(ptr, align); - adjusted_size = size + (aligned - m_chunk_list.m_ptr); + adjusted_size = size + static_cast(aligned - m_chunk_list.m_ptr); } m_chunk_list.m_free -= adjusted_size; m_chunk_list.m_ptr += adjusted_size; diff --git a/include/msgpack/v1/detail/cpp11_zone.hpp b/include/msgpack/v1/detail/cpp11_zone.hpp index 04659ba6..c3cf3f6b 100644 --- a/include/msgpack/v1/detail/cpp11_zone.hpp +++ b/include/msgpack/v1/detail/cpp11_zone.hpp @@ -61,7 +61,7 @@ private: ++m_tail; } void push_expand(void (*func)(void*), void* data) { - const size_t nused = m_end - m_array; + const size_t nused = static_cast(m_end - m_array); size_t nnext; if(nused == 0) { nnext = (sizeof(finalizer) < 72/2) ? @@ -239,12 +239,12 @@ inline char* zone::get_aligned(char* ptr, size_t align) inline void* zone::allocate_align(size_t size, size_t align) { char* aligned = get_aligned(m_chunk_list.m_ptr, align); - size_t adjusted_size = size + (aligned - m_chunk_list.m_ptr); + size_t adjusted_size = size + static_cast(aligned - m_chunk_list.m_ptr); if (m_chunk_list.m_free < adjusted_size) { size_t enough_size = size + align - 1; char* ptr = allocate_expand(enough_size); aligned = get_aligned(ptr, align); - adjusted_size = size + (aligned - m_chunk_list.m_ptr); + adjusted_size = size + static_cast(aligned - m_chunk_list.m_ptr); } m_chunk_list.m_free -= adjusted_size; m_chunk_list.m_ptr += adjusted_size; diff --git a/include/msgpack/v1/object.hpp b/include/msgpack/v1/object.hpp index 793e40fb..231b389f 100644 --- a/include/msgpack/v1/object.hpp +++ b/include/msgpack/v1/object.hpp @@ -352,7 +352,7 @@ struct object_pack_visitor { return true; } bool visit_ext(const char* v, uint32_t size) { - m_packer.pack_ext(size - 1, *v); + m_packer.pack_ext(size - 1, static_cast(*v)); m_packer.pack_ext_body(v + 1, size - 1); return true; } @@ -467,7 +467,7 @@ struct object_stringize_visitor { return true; } bool visit_bin(const char* v, uint32_t size) { - (m_os << '"').write(v, size) << '"'; + (m_os << '"').write(v, static_cast(size)) << '"'; return true; } bool visit_ext(const char* /*v*/, uint32_t /*size*/) { diff --git a/include/msgpack/v1/object_fwd.hpp b/include/msgpack/v1/object_fwd.hpp index a932226a..66bf4ad1 100644 --- a/include/msgpack/v1/object_fwd.hpp +++ b/include/msgpack/v1/object_fwd.hpp @@ -40,7 +40,7 @@ struct object_bin { }; struct object_ext { - int8_t type() const { return ptr[0]; } + int8_t type() const { return static_cast(ptr[0]); } const char* data() const { return &ptr[1]; } uint32_t size; const char* ptr; diff --git a/include/msgpack/v1/pack.hpp b/include/msgpack/v1/pack.hpp index 26e271ce..14da8642 100644 --- a/include/msgpack/v1/pack.hpp +++ b/include/msgpack/v1/pack.hpp @@ -16,6 +16,7 @@ #include #include #include +#include namespace msgpack { @@ -618,7 +619,33 @@ private: void pack_imp_int64(T d); void append_buffer(const char* buf, size_t len) - { m_stream.write(buf, len); } + { + append_buffer(m_stream, &Stream::write, buf, len); + } + + template + typename enable_if< + is_same< + std::ostream& (std::ostream::*)(const char*, std::streamsize), + Write + >::value + >::type + append_buffer(S& s, Write, const char* buf, size_t len) + { + s.write(buf, static_cast(len)); + } + + template + typename enable_if< + !is_same< + std::ostream& (std::ostream::*)(const char*, std::streamsize), + Write + >::value + >::type + append_buffer(S& s, Write, const char* buf, size_t len) + { + s.write(buf, len); + } private: Stream& m_stream; @@ -795,7 +822,7 @@ template inline packer& packer::pack_fix_int16(int16_t d) { char buf[3]; - buf[0] = static_cast(0xd1u); _msgpack_store16(&buf[1], d); + buf[0] = static_cast(0xd1u); _msgpack_store16(&buf[1], (uint16_t)d); append_buffer(buf, 3); return *this; } @@ -804,7 +831,7 @@ template inline packer& packer::pack_fix_int32(int32_t d) { char buf[5]; - buf[0] = static_cast(0xd2u); _msgpack_store32(&buf[1], d); + buf[0] = static_cast(0xd2u); _msgpack_store32(&buf[1], (uint32_t)d); append_buffer(buf, 5); return *this; } @@ -1228,7 +1255,7 @@ inline packer& packer::pack_str(uint32_t l) append_buffer(&buf, 1); } else if(l < 256) { char buf[2]; - buf[0] = static_cast(0xd9u); buf[1] = static_cast(l); + buf[0] = static_cast(0xd9u); buf[1] = static_cast(l); append_buffer(buf, 2); } else if(l < 65536) { char buf[3]; @@ -1282,7 +1309,7 @@ inline packer& packer::pack_bin(uint32_t l) { if(l < 256) { char buf[2]; - buf[0] = static_cast(0xc4u); buf[1] = static_cast(l); + buf[0] = static_cast(0xc4u); buf[1] = static_cast(l); append_buffer(buf, 2); } else if(l < 65536) { char buf[3]; diff --git a/include/msgpack/v1/unpack.hpp b/include/msgpack/v1/unpack.hpp index 74836bd3..7bce8267 100644 --- a/include/msgpack/v1/unpack.hpp +++ b/include/msgpack/v1/unpack.hpp @@ -78,19 +78,19 @@ inline void unpack_uint64(uint64_t d, msgpack::object& o) { o.type = msgpack::type::POSITIVE_INTEGER; o.via.u64 = d; } inline void unpack_int8(int8_t d, msgpack::object& o) -{ if(d >= 0) { o.type = msgpack::type::POSITIVE_INTEGER; o.via.u64 = d; } +{ if(d >= 0) { o.type = msgpack::type::POSITIVE_INTEGER; o.via.u64 = static_cast(d); } else { o.type = msgpack::type::NEGATIVE_INTEGER; o.via.i64 = d; } } inline void unpack_int16(int16_t d, msgpack::object& o) -{ if(d >= 0) { o.type = msgpack::type::POSITIVE_INTEGER; o.via.u64 = d; } +{ if(d >= 0) { o.type = msgpack::type::POSITIVE_INTEGER; o.via.u64 = static_cast(d); } else { o.type = msgpack::type::NEGATIVE_INTEGER; o.via.i64 = d; } } inline void unpack_int32(int32_t d, msgpack::object& o) -{ if(d >= 0) { o.type = msgpack::type::POSITIVE_INTEGER; o.via.u64 = d; } +{ if(d >= 0) { o.type = msgpack::type::POSITIVE_INTEGER; o.via.u64 = static_cast(d); } else { o.type = msgpack::type::NEGATIVE_INTEGER; o.via.i64 = d; } } inline void unpack_int64(int64_t d, msgpack::object& o) -{ if(d >= 0) { o.type = msgpack::type::POSITIVE_INTEGER; o.via.u64 = d; } +{ if(d >= 0) { o.type = msgpack::type::POSITIVE_INTEGER; o.via.u64 = static_cast(d); } else { o.type = msgpack::type::NEGATIVE_INTEGER; o.via.i64 = d; } } inline void unpack_float(float d, msgpack::object& o) @@ -418,10 +418,10 @@ private: m_stack[0].set_obj(obj); ++m_current; /*printf("-- finish --\n"); */ - off = m_current - m_start; + off = static_cast(m_current - m_start); } else if (ret < 0) { - off = m_current - m_start; + off = static_cast(m_current - m_start); } else { m_cs = MSGPACK_CS_HEADER; @@ -461,7 +461,7 @@ inline int context::execute(const char* data, std::size_t len, std::size_t& off) msgpack::object obj; if(m_current == pe) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return 0; } bool fixed_trail_again = false; @@ -544,7 +544,7 @@ inline int context::execute(const char* data, std::size_t len, std::size_t& off) int ret = push_proc(obj, off); if (ret != 0) return ret; } else { - off = m_current - m_start; + off = static_cast(m_current - m_start); return -1; } // end MSGPACK_CS_HEADER @@ -555,7 +555,7 @@ inline int context::execute(const char* data, std::size_t len, std::size_t& off) fixed_trail_again = false; } if(static_cast(pe - m_current) < m_trail) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return 0; } n = m_current; @@ -830,13 +830,13 @@ inline int context::execute(const char* data, std::size_t len, std::size_t& off) if (ret != 0) return ret; } break; default: - off = m_current - m_start; + off = static_cast(m_current - m_start); return -1; } } } while(m_current != pe); - off = m_current - m_start; + off = static_cast(m_current - m_start); return 0; } diff --git a/include/msgpack/v1/vrefbuffer.hpp b/include/msgpack/v1/vrefbuffer.hpp index 39bcd69c..e07c1b05 100644 --- a/include/msgpack/v1/vrefbuffer.hpp +++ b/include/msgpack/v1/vrefbuffer.hpp @@ -117,7 +117,7 @@ public: void append_ref(const char* buf, size_t len) { if(m_tail == m_end) { - const size_t nused = m_tail - m_array; + const size_t nused = static_cast(m_tail - m_array); const size_t nnext = nused * 2; iovec* nvec = static_cast(::realloc( @@ -145,11 +145,11 @@ public: if(sz < len) { sz = len; } - + if(sizeof(chunk) + sz < sz){ throw std::bad_alloc(); } - + chunk* c = static_cast(::malloc(sizeof(chunk) + sz)); if(!c) { throw std::bad_alloc(); @@ -184,7 +184,7 @@ public: size_t vector_size() const { - return m_tail - m_array; + return static_cast(m_tail - m_array); } void migrate(vrefbuffer* to) @@ -202,11 +202,11 @@ public: empty->next = MSGPACK_NULLPTR; - const size_t nused = m_tail - m_array; + const size_t nused = static_cast(m_tail - m_array); if(to->m_tail + nused < m_end) { - const size_t tosize = to->m_tail - to->m_array; + const size_t tosize = static_cast(to->m_tail - to->m_array); const size_t reqsize = nused + tosize; - size_t nnext = (to->m_end - to->m_array) * 2; + size_t nnext = static_cast(to->m_end - to->m_array) * 2; while(nnext < reqsize) { size_t tmp_nnext = nnext * 2; if (tmp_nnext <= nnext) { diff --git a/include/msgpack/v1/zbuffer.hpp b/include/msgpack/v1/zbuffer.hpp index e34b48ed..c50c2792 100644 --- a/include/msgpack/v1/zbuffer.hpp +++ b/include/msgpack/v1/zbuffer.hpp @@ -47,7 +47,7 @@ public: void write(const char* buf, size_t len) { m_stream.next_in = reinterpret_cast(const_cast(buf)); - m_stream.avail_in = len; + m_stream.avail_in = static_cast(len); while(m_stream.avail_in > 0) { if(m_stream.avail_out < MSGPACK_ZBUFFER_RESERVE_SIZE) { @@ -91,7 +91,7 @@ public: size_t size() const { - return reinterpret_cast(m_stream.next_out) - m_data; + return static_cast(reinterpret_cast(m_stream.next_out) - m_data); } void reset() @@ -104,7 +104,7 @@ public: void reset_buffer() { - m_stream.avail_out += reinterpret_cast(m_stream.next_out) - m_data; + m_stream.avail_out += static_cast(reinterpret_cast(m_stream.next_out) - m_data); m_stream.next_out = reinterpret_cast(m_data); } @@ -120,7 +120,7 @@ public: private: bool expand() { - size_t used = reinterpret_cast(m_stream.next_out) - m_data; + size_t used = static_cast(reinterpret_cast(m_stream.next_out) - m_data); size_t csize = used + m_stream.avail_out; size_t nsize = (csize == 0) ? m_init_size : csize * 2; @@ -131,7 +131,7 @@ private: m_data = tmp; m_stream.next_out = reinterpret_cast(tmp + used); - m_stream.avail_out = nsize - used; + m_stream.avail_out = static_cast(nsize - used); return true; } diff --git a/include/msgpack/v2/create_object_visitor.hpp b/include/msgpack/v2/create_object_visitor.hpp index 78c47ea8..7ca24b6b 100644 --- a/include/msgpack/v2/create_object_visitor.hpp +++ b/include/msgpack/v2/create_object_visitor.hpp @@ -85,7 +85,7 @@ public: msgpack::object* obj = m_stack.back(); if(v >= 0) { obj->type = msgpack::type::POSITIVE_INTEGER; - obj->via.u64 = v; + obj->via.u64 = static_cast(v); } else { obj->type = msgpack::type::NEGATIVE_INTEGER; diff --git a/include/msgpack/v2/parse.hpp b/include/msgpack/v2/parse.hpp index becbed45..88a693ca 100644 --- a/include/msgpack/v2/parse.hpp +++ b/include/msgpack/v2/parse.hpp @@ -71,27 +71,27 @@ private: ++m_current; if (size == 0) { if (!sv(size)) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return PARSE_STOP_VISITOR; } if (!ev()) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return PARSE_STOP_VISITOR; } parse_return ret = m_stack.consume(holder()); if (ret != PARSE_CONTINUE) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return ret; } } else { if (!sv(size)) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return PARSE_STOP_VISITOR; } parse_return ret = m_stack.push(holder(), sv.type(), static_cast(size)); if (ret != PARSE_CONTINUE) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return ret; } } @@ -102,12 +102,12 @@ private: parse_return after_visit_proc(bool visit_result, std::size_t& off) { ++m_current; if (!visit_result) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return PARSE_STOP_VISITOR; } parse_return ret = m_stack.consume(holder()); if (ret != PARSE_CONTINUE) { - off = m_current - m_start; + off = static_cast(m_current - m_start); } m_cs = MSGPACK_CS_HEADER; return ret; @@ -244,7 +244,7 @@ inline parse_return context::execute(const char* data, std::size_ msgpack::object obj; if(m_current == pe) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return PARSE_CONTINUE; } bool fixed_trail_again = false; @@ -326,7 +326,7 @@ inline parse_return context::execute(const char* data, std::size_ parse_return upr = after_visit_proc(visret, off); if (upr != PARSE_CONTINUE) return upr; } else { - off = m_current - m_start; + off = static_cast(m_current - m_start); holder().visitor().parse_error(off - 1, off); return PARSE_PARSE_ERROR; } @@ -338,7 +338,7 @@ inline parse_return context::execute(const char* data, std::size_ fixed_trail_again = false; } if(static_cast(pe - m_current) < m_trail) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return PARSE_CONTINUE; } n = m_current; @@ -608,14 +608,14 @@ inline parse_return context::execute(const char* data, std::size_ if (ret != PARSE_CONTINUE) return ret; } break; default: - off = m_current - m_start; - holder().visitor().parse_error(n - m_start - 1, n - m_start); + off = static_cast(m_current - m_start); + holder().visitor().parse_error(static_cast(n - m_start - 1), static_cast(n - m_start)); return PARSE_PARSE_ERROR; } } } while(m_current != pe); - off = m_current - m_start; + off = static_cast(m_current - m_start); return PARSE_CONTINUE; } diff --git a/include/msgpack/v2/x3_parse.hpp b/include/msgpack/v2/x3_parse.hpp index 50a0db44..b55fb2cf 100644 --- a/include/msgpack/v2/x3_parse.hpp +++ b/include/msgpack/v2/x3_parse.hpp @@ -22,6 +22,7 @@ #if __GNUC__ >= 4 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wconversion" #endif // __GNUC__ >= 4 #include @@ -202,7 +203,7 @@ const auto mp_object_def = ( [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); - std::int8_t val = _attr(ctx); + std::int8_t val = static_cast(_attr(ctx)); app_specific.vis.visit_negative_integer(val); } ) @@ -253,7 +254,7 @@ const auto mp_object_def = ( [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); - std::int8_t val = _attr(ctx); + std::int8_t val = static_cast(_attr(ctx)); app_specific.vis.visit_negative_integer(val); } ) @@ -264,7 +265,7 @@ const auto mp_object_def = ( [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); - std::int16_t val = _attr(ctx); + std::int16_t val = static_cast(_attr(ctx)); app_specific.vis.visit_negative_integer(val); } ) @@ -275,7 +276,7 @@ const auto mp_object_def = ( [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); - std::int32_t val = _attr(ctx); + std::int32_t val = static_cast(_attr(ctx)); app_specific.vis.visit_negative_integer(val); } ) @@ -286,7 +287,7 @@ const auto mp_object_def = ( [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); - std::int64_t val = _attr(ctx); + std::int64_t val = static_cast(_attr(ctx)); app_specific.vis.visit_negative_integer(val); } ) @@ -339,7 +340,7 @@ const auto mp_object_def = [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); auto const& str = _attr(ctx); - std::size_t size = std::distance(str.begin(), str.end()); + auto size = static_cast(std::distance(str.begin(), str.end())); app_specific.vis.visit_str(size ? &str.front() : nullptr, size); } ) @@ -363,7 +364,7 @@ const auto mp_object_def = [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); auto const& str = _attr(ctx); - std::size_t size = std::distance(str.begin(), str.end()); + auto size = static_cast(std::distance(str.begin(), str.end())); app_specific.vis.visit_str(size ? &str.front() : nullptr, size); } ) @@ -387,7 +388,7 @@ const auto mp_object_def = [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); auto const& str = _attr(ctx); - std::size_t size = std::distance(str.begin(), str.end()); + auto size = static_cast(std::distance(str.begin(), str.end())); app_specific.vis.visit_str(size ? &str.front() : nullptr, size); } ) @@ -411,7 +412,7 @@ const auto mp_object_def = [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); auto const& str = _attr(ctx); - std::size_t size = std::distance(str.begin(), str.end()); + auto size = static_cast(std::distance(str.begin(), str.end())); app_specific.vis.visit_str(size ? &str.front() : nullptr, size); } ) @@ -435,7 +436,7 @@ const auto mp_object_def = [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); auto const& bin = _attr(ctx); - std::size_t size = std::distance(bin.begin(), bin.end()); + auto size = static_cast(std::distance(bin.begin(), bin.end())); app_specific.vis.visit_bin(size ? &bin.front() : nullptr, size); } ) @@ -459,7 +460,7 @@ const auto mp_object_def = [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); auto const& bin = _attr(ctx); - std::size_t size = std::distance(bin.begin(), bin.end()); + auto size = static_cast(std::distance(bin.begin(), bin.end())); app_specific.vis.visit_bin(size ? &bin.front() : nullptr, size); } ) @@ -483,7 +484,7 @@ const auto mp_object_def = [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); auto const& bin = _attr(ctx); - std::size_t size = std::distance(bin.begin(), bin.end()); + auto size = static_cast(std::distance(bin.begin(), bin.end())); app_specific.vis.visit_bin(size ? &bin.front() : nullptr, size); } ) @@ -494,7 +495,7 @@ const auto mp_object_def = ( [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); - std::size_t size = _attr(ctx) & 0b00001111; + uint32_t size = _attr(ctx) & 0b00001111; app_specific.index_sizes.emplace_back(size, index_size::type_t::array); app_specific.vis.start_array(size); } @@ -508,7 +509,7 @@ const auto mp_object_def = ( [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); - std::size_t size = _attr(ctx); + uint32_t size = _attr(ctx); app_specific.index_sizes.emplace_back(size, index_size::type_t::array); app_specific.vis.start_array(size); } @@ -522,7 +523,7 @@ const auto mp_object_def = ( [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); - std::size_t size = _attr(ctx); + uint32_t size = _attr(ctx); app_specific.index_sizes.emplace_back(size, index_size::type_t::array); app_specific.vis.start_array(size); } @@ -536,7 +537,7 @@ const auto mp_object_def = ( [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); - std::size_t size = _attr(ctx) & 0b00001111; + uint32_t size = _attr(ctx) & 0b00001111; app_specific.index_sizes.emplace_back(size, index_size::type_t::map); app_specific.vis.start_map(size); } @@ -550,7 +551,7 @@ const auto mp_object_def = ( [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); - std::size_t size = _attr(ctx); + uint32_t size = _attr(ctx); app_specific.index_sizes.emplace_back(size, index_size::type_t::map); app_specific.vis.start_map(size); } @@ -564,7 +565,7 @@ const auto mp_object_def = ( [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); - std::size_t size = _attr(ctx); + uint32_t size = _attr(ctx); app_specific.index_sizes.emplace_back(size, index_size::type_t::map); app_specific.vis.start_map(size); } @@ -591,7 +592,7 @@ const auto mp_object_def = [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); auto const& ext = _attr(ctx); - std::size_t size = std::distance(ext.begin(), ext.end()); + auto size = static_cast(std::distance(ext.begin(), ext.end())); app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size); } ) @@ -615,7 +616,7 @@ const auto mp_object_def = [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); auto const& ext = _attr(ctx); - std::size_t size = std::distance(ext.begin(), ext.end()); + auto size = static_cast(std::distance(ext.begin(), ext.end())); app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size); } ) @@ -639,7 +640,7 @@ const auto mp_object_def = [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); auto const& ext = _attr(ctx); - std::size_t size = std::distance(ext.begin(), ext.end()); + auto size = static_cast(std::distance(ext.begin(), ext.end())); app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size); } ) @@ -663,7 +664,7 @@ const auto mp_object_def = [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); auto const& ext = _attr(ctx); - std::size_t size = std::distance(ext.begin(), ext.end()); + auto size = static_cast(std::distance(ext.begin(), ext.end())); app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size); } ) @@ -687,7 +688,7 @@ const auto mp_object_def = [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); auto const& ext = _attr(ctx); - std::size_t size = std::distance(ext.begin(), ext.end()); + auto size = static_cast(std::distance(ext.begin(), ext.end())); app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size); } ) @@ -711,7 +712,7 @@ const auto mp_object_def = [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); auto const& ext = _attr(ctx); - std::size_t size = std::distance(ext.begin(), ext.end()); + auto size = static_cast(std::distance(ext.begin(), ext.end())); app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size); } ) @@ -735,7 +736,7 @@ const auto mp_object_def = [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); auto const& ext = _attr(ctx); - std::size_t size = std::distance(ext.begin(), ext.end()); + auto size = static_cast(std::distance(ext.begin(), ext.end())); app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size); } ) @@ -759,7 +760,7 @@ const auto mp_object_def = [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); auto const& ext = _attr(ctx); - std::size_t size = std::distance(ext.begin(), ext.end()); + auto size = static_cast(std::distance(ext.begin(), ext.end())); app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size); } ) @@ -771,6 +772,7 @@ const auto array_item_def = [](auto& ctx){ auto& app_specific = x3::get(ctx).get(); app_specific.vis.start_array_item(); + _pass(ctx) = true; } ) diff --git a/include/msgpack/v3/parse.hpp b/include/msgpack/v3/parse.hpp index b833f3e3..3050da7a 100644 --- a/include/msgpack/v3/parse.hpp +++ b/include/msgpack/v3/parse.hpp @@ -63,29 +63,29 @@ private: load(size, load_pos); if (size == 0) { if (!sv(size)) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return PARSE_STOP_VISITOR; } if (!ev()) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return PARSE_STOP_VISITOR; } parse_return ret = m_stack.consume(holder(), m_current); ++m_current; if (ret != PARSE_CONTINUE) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return ret; } } else { if (!sv(size)) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return PARSE_STOP_VISITOR; } parse_return ret = m_stack.push(holder(), sv.type(), static_cast(size)); ++m_current; if (ret != PARSE_CONTINUE) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return ret; } } @@ -95,13 +95,13 @@ private: parse_return after_visit_proc(bool visit_result, std::size_t& off) { if (!visit_result) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return PARSE_STOP_VISITOR; } parse_return ret = m_stack.consume(holder(), m_current); ++m_current; if (ret != PARSE_CONTINUE) { - off = m_current - m_start; + off = static_cast(m_current - m_start); } m_cs = MSGPACK_CS_HEADER; return ret; @@ -253,7 +253,7 @@ inline parse_return context::execute(const char* data, std::size_ msgpack::object obj; if(m_current == pe) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return PARSE_CONTINUE; } bool fixed_trail_again = false; @@ -335,7 +335,7 @@ inline parse_return context::execute(const char* data, std::size_ parse_return upr = after_visit_proc(visret, off); if (upr != PARSE_CONTINUE) return upr; } else { - off = m_current - m_start; + off = static_cast(m_current - m_start); holder().visitor().parse_error(off - 1, off); return PARSE_PARSE_ERROR; } @@ -347,7 +347,7 @@ inline parse_return context::execute(const char* data, std::size_ fixed_trail_again = false; } if(static_cast(pe - m_current) < m_trail) { - off = m_current - m_start; + off = static_cast(m_current - m_start); return PARSE_CONTINUE; } n = m_current; @@ -617,14 +617,14 @@ inline parse_return context::execute(const char* data, std::size_ if (ret != PARSE_CONTINUE) return ret; } break; default: - off = m_current - m_start; - holder().visitor().parse_error(n - m_start - 1, n - m_start); + off = static_cast(m_current - m_start); + holder().visitor().parse_error(static_cast(n - m_start - 1), static_cast(n - m_start)); return PARSE_PARSE_ERROR; } } } while(m_current != pe); - off = m_current - m_start; + off = static_cast(m_current - m_start); return PARSE_CONTINUE; } diff --git a/include/msgpack/zbuffer.h b/include/msgpack/zbuffer.h index e6f742b6..aac07c13 100644 --- a/include/msgpack/zbuffer.h +++ b/include/msgpack/zbuffer.h @@ -100,8 +100,9 @@ static inline void msgpack_zbuffer_free(msgpack_zbuffer* zbuf) static inline bool msgpack_zbuffer_expand(msgpack_zbuffer* zbuf) { - size_t used = (char*)zbuf->stream.next_out - zbuf->data; + size_t used = static_cast(reinterpret_cast(zbuf->stream.next_out) - zbuf->data); size_t csize = used + zbuf->stream.avail_out; + size_t nsize = (csize == 0) ? zbuf->init_size : csize * 2; char* tmp = (char*)realloc(zbuf->data, nsize); @@ -111,7 +112,7 @@ static inline bool msgpack_zbuffer_expand(msgpack_zbuffer* zbuf) zbuf->data = tmp; zbuf->stream.next_out = (Bytef*)(tmp + used); - zbuf->stream.avail_out = nsize - used; + zbuf->stream.avail_out = static_cast(nsize - used); return true; } @@ -121,7 +122,7 @@ static inline int msgpack_zbuffer_write(void* data, const char* buf, size_t len) msgpack_zbuffer* zbuf = (msgpack_zbuffer*)data; zbuf->stream.next_in = (Bytef*)buf; - zbuf->stream.avail_in = len; + zbuf->stream.avail_in = static_cast(len); while(zbuf->stream.avail_in > 0) { if(zbuf->stream.avail_out < MSGPACK_ZBUFFER_RESERVE_SIZE) { @@ -162,12 +163,12 @@ static inline const char* msgpack_zbuffer_data(const msgpack_zbuffer* zbuf) static inline size_t msgpack_zbuffer_size(const msgpack_zbuffer* zbuf) { - return (char*)zbuf->stream.next_out - zbuf->data; + return static_cast(reinterpret_cast(zbuf->stream.next_out) - zbuf->data); } static inline void msgpack_zbuffer_reset_buffer(msgpack_zbuffer* zbuf) { - zbuf->stream.avail_out += (char*)zbuf->stream.next_out - zbuf->data; + zbuf->stream.avail_out += (uInt)((char*)zbuf->stream.next_out - zbuf->data); zbuf->stream.next_out = (Bytef*)zbuf->data; } @@ -197,4 +198,3 @@ static inline char* msgpack_zbuffer_release_buffer(msgpack_zbuffer* zbuf) #endif #endif /* msgpack/zbuffer.h */ - diff --git a/include/msgpack/zone.h b/include/msgpack/zone.h index 55229d71..9005be79 100644 --- a/include/msgpack/zone.h +++ b/include/msgpack/zone.h @@ -111,7 +111,7 @@ static inline void* msgpack_zone_malloc(msgpack_zone* zone, size_t size) zone->chunk_list.ptr + (MSGPACK_ZONE_ALIGN - 1) ) / MSGPACK_ZONE_ALIGN * MSGPACK_ZONE_ALIGN ); - size_t adjusted_size = size + (aligned - zone->chunk_list.ptr); + size_t adjusted_size = size + (size_t)(aligned - zone->chunk_list.ptr); if(zone->chunk_list.free >= adjusted_size) { zone->chunk_list.free -= adjusted_size; zone->chunk_list.ptr += adjusted_size; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 797d7005..2cbc2d6e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -89,7 +89,7 @@ FOREACH (source_file ${check_PROGRAMS}) ) ADD_TEST (${source_file_we} ${source_file_we}) IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wall -Wextra") + SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wall -Wextra -Wconversion") ENDIF () IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-mismatched-tags") diff --git a/test/array_ref.cpp b/test/array_ref.cpp index ce00b7a7..cb58f2c7 100644 --- a/test/array_ref.cpp +++ b/test/array_ref.cpp @@ -3,8 +3,13 @@ #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/test/boost_fusion.cpp b/test/boost_fusion.cpp index 88c30e96..c6859a4b 100644 --- a/test/boost_fusion.cpp +++ b/test/boost_fusion.cpp @@ -3,8 +3,13 @@ #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/test/boost_optional.cpp b/test/boost_optional.cpp index a038c6ec..b029f8c0 100644 --- a/test/boost_optional.cpp +++ b/test/boost_optional.cpp @@ -1,8 +1,15 @@ #include #include #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/test/boost_string_ref.cpp b/test/boost_string_ref.cpp index f0433278..6554cd7c 100644 --- a/test/boost_string_ref.cpp +++ b/test/boost_string_ref.cpp @@ -1,8 +1,15 @@ #include #include #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/test/boost_string_view.cpp b/test/boost_string_view.cpp index f68ad0df..ce02ab5e 100644 --- a/test/boost_string_view.cpp +++ b/test/boost_string_view.cpp @@ -1,8 +1,14 @@ #include #include #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/test/boost_variant.cpp b/test/boost_variant.cpp index e11bc285..ab9a791f 100644 --- a/test/boost_variant.cpp +++ b/test/boost_variant.cpp @@ -2,8 +2,14 @@ #include #include #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -393,10 +399,10 @@ TEST(MSGPACK_BOOST, object_with_zone_variant_raw_ref) v.push_back('a'); v.push_back('b'); v.push_back('c'); - msgpack::type::raw_ref rr(&v.front(), v.size()); + msgpack::type::raw_ref rr(&v.front(), static_cast(v.size())); msgpack::type::variant val1 = rr; EXPECT_TRUE(val1.is_raw_ref()); - EXPECT_EQ(val1.as_raw_ref(), msgpack::type::raw_ref(&v.front(), v.size())); + EXPECT_EQ(val1.as_raw_ref(), msgpack::type::raw_ref(&v.front(), static_cast(v.size()))); msgpack::object obj(val1, z); msgpack::type::variant val2 = obj.as(); // Converted as std::vector. @@ -418,7 +424,7 @@ TEST(MSGPACK_BOOST, pack_convert_variant_ext) v.push_back('a'); v.push_back('b'); v.push_back('c'); - msgpack::type::ext e(42, v.data(), v.size()); + msgpack::type::ext e(42, v.data(), static_cast(v.size())); msgpack::type::variant val1(e); EXPECT_TRUE(val1.is_ext()); EXPECT_EQ(val1.as_ext(), e); @@ -443,7 +449,7 @@ TEST(MSGPACK_BOOST, object_with_zone_variant_ext) v.push_back('a'); v.push_back('b'); v.push_back('c'); - msgpack::type::ext e(42, v.data(), v.size()); + msgpack::type::ext e(42, v.data(), static_cast(v.size())); msgpack::type::variant val1(e); EXPECT_TRUE(val1.is_ext()); EXPECT_EQ(val1.as_ext(), e); @@ -463,7 +469,7 @@ TEST(MSGPACK_BOOST, object_with_zone_variant_ext_ref) v.push_back('a'); v.push_back('b'); v.push_back('c'); - msgpack::type::ext_ref e(v.data(), v.size()); + msgpack::type::ext_ref e(v.data(), static_cast(v.size())); msgpack::type::variant val1(e); EXPECT_TRUE(val1.is_ext_ref()); EXPECT_EQ(val1.as_ext_ref(), e); @@ -616,7 +622,7 @@ TEST(MSGPACK_BOOST, pack_convert_variant_ref_bin) v.push_back('a'); v.push_back('b'); v.push_back('c'); - msgpack::type::raw_ref rr(v.data(), v.size()); + msgpack::type::raw_ref rr(v.data(), static_cast(v.size())); msgpack::type::variant_ref val1 = rr; EXPECT_TRUE(val1.is_raw_ref()); EXPECT_EQ(val1.as_raw_ref(), rr); @@ -641,7 +647,7 @@ TEST(MSGPACK_BOOST, object_with_zone_variant_ref_bin) v.push_back('a'); v.push_back('b'); v.push_back('c'); - msgpack::type::raw_ref rr(v.data(), v.size()); + msgpack::type::raw_ref rr(v.data(), static_cast(v.size())); msgpack::type::variant_ref val1 = rr; EXPECT_TRUE(val1.is_raw_ref()); EXPECT_EQ(val1.as_raw_ref(), rr); @@ -663,7 +669,7 @@ TEST(MSGPACK_BOOST, pack_convert_variant_ref_ext) v.push_back('a'); v.push_back('b'); v.push_back('c'); - msgpack::type::ext_ref er(v.data(), v.size()); + msgpack::type::ext_ref er(v.data(), static_cast(v.size())); msgpack::type::variant_ref val1(er); EXPECT_TRUE(val1.is_ext_ref()); EXPECT_EQ(val1.as_ext_ref(), er); @@ -688,7 +694,7 @@ TEST(MSGPACK_BOOST, object_with_zone_variant_ref_ext) v.push_back('a'); v.push_back('b'); v.push_back('c'); - msgpack::type::ext_ref er(v.data(), v.size()); + msgpack::type::ext_ref er(v.data(), static_cast(v.size())); msgpack::type::variant_ref val1(er); EXPECT_TRUE(val1.is_ext_ref()); EXPECT_EQ(val1.as_ext_ref(), er); diff --git a/test/buffer.cpp b/test/buffer.cpp index 773a2a77..18cc7aac 100644 --- a/test/buffer.cpp +++ b/test/buffer.cpp @@ -3,7 +3,14 @@ #include #include #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include + +#pragma GCC diagnostic pop + #include TEST(buffer, sbuffer) diff --git a/test/carray.cpp b/test/carray.cpp index 9c7d1009..2def7d6f 100644 --- a/test/carray.cpp +++ b/test/carray.cpp @@ -1,5 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include + +#pragma GCC diagnostic pop + #include TEST(carray, pack_unpack_int) diff --git a/test/cases.cpp b/test/cases.cpp index 78a6f592..c0ae207e 100644 --- a/test/cases.cpp +++ b/test/cases.cpp @@ -1,13 +1,19 @@ #include #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + static void feed_file(msgpack::unpacker& pac, const char* path) { std::ifstream fin(path); while(true) { pac.reserve_buffer(32*1024); - fin.read(pac.buffer(), pac.buffer_capacity()); + fin.read(pac.buffer(), static_cast(pac.buffer_capacity())); if(fin.bad()) { throw std::runtime_error("read failed"); } diff --git a/test/convert.cpp b/test/convert.cpp index 38d8026f..9e1de4a7 100644 --- a/test/convert.cpp +++ b/test/convert.cpp @@ -1,6 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + class enum_member { public: enum_member() : flag(A) { } diff --git a/test/fixint.cpp b/test/fixint.cpp index 713cfb36..4aa951f7 100644 --- a/test/fixint.cpp +++ b/test/fixint.cpp @@ -1,6 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + template void check_size(size_t size) { T v(0); @@ -25,7 +31,7 @@ TEST(fixint, size) template void check_convert() { - T v1(-11); + T v1(typename T::value_type(-11)); msgpack::sbuffer sbuf; msgpack::pack(sbuf, v1); diff --git a/test/fixint_c.cpp b/test/fixint_c.cpp index d9dc5180..2060c90f 100644 --- a/test/fixint_c.cpp +++ b/test/fixint_c.cpp @@ -1,6 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + TEST(fixint, size) { msgpack_sbuffer* sbuf = msgpack_sbuffer_new(); @@ -29,4 +35,3 @@ TEST(fixint, size) msgpack_sbuffer_free(sbuf); msgpack_packer_free(pk); } - diff --git a/test/fuzz_unpack_pack_fuzzer_cpp11.cpp b/test/fuzz_unpack_pack_fuzzer_cpp11.cpp index 337db3c3..956a7f62 100644 --- a/test/fuzz_unpack_pack_fuzzer_cpp11.cpp +++ b/test/fuzz_unpack_pack_fuzzer_cpp11.cpp @@ -1,5 +1,10 @@ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #include "../fuzz/unpack_pack_fuzzer.cpp" TEST(FUZZ_UNPACK_PACK_FUZZER, works) diff --git a/test/iterator_cpp11.cpp b/test/iterator_cpp11.cpp index c5a925cd..4062f13b 100644 --- a/test/iterator_cpp11.cpp +++ b/test/iterator_cpp11.cpp @@ -1,6 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/test/json.cpp b/test/json.cpp index 3b4f4239..33d00cae 100644 --- a/test/json.cpp +++ b/test/json.cpp @@ -1,8 +1,14 @@ #include #include #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + TEST(json, basic_elements) { typedef std::map map_s_i; diff --git a/test/limit.cpp b/test/limit.cpp index bc485210..a5cbad7e 100644 --- a/test/limit.cpp +++ b/test/limit.cpp @@ -1,5 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include + +#pragma GCC diagnostic pop + #include TEST(limit, unpack_array_no_over) diff --git a/test/msgpack_basic.cpp b/test/msgpack_basic.cpp index 47a41bef..48968a1f 100644 --- a/test/msgpack_basic.cpp +++ b/test/msgpack_basic.cpp @@ -9,8 +9,13 @@ #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #if defined(_MSC_VER) || defined(__MINGW32__) #define msgpack_rand() ((double)rand() / RAND_MAX) #else // _MSC_VER || __MINGW32__ @@ -36,7 +41,7 @@ const double kEPS = 1e-10; v.push_back(numeric_limits::min()); \ v.push_back(numeric_limits::max()); \ for (unsigned int i = 0; i < kLoop; i++) \ - v.push_back(rand()); \ + v.push_back(static_cast(rand())); \ for (unsigned int i = 0; i < v.size() ; i++) { \ msgpack::sbuffer sbuf; \ test_type val1 = v[i]; \ @@ -209,7 +214,7 @@ TYPED_TEST_P(IntegerToFloatingPointTest, simple_buffer) vector v; v.push_back(0); v.push_back(1); - if (numeric_limits::is_signed) v.push_back(-1); + if (numeric_limits::is_signed) v.push_back(static_cast(-1)); else v.push_back(2); for (unsigned int i = 0; i < kLoop; i++) { v.push_back(rand() % 0x7FFFFF); @@ -221,7 +226,7 @@ TYPED_TEST_P(IntegerToFloatingPointTest, simple_buffer) msgpack::object_handle oh = msgpack::unpack(sbuf.data(), sbuf.size()); float_type val2 = oh.get().as(); - EXPECT_TRUE(fabs(val2 - val1) <= kEPS); + EXPECT_TRUE(fabs(val2 - static_cast(val1)) <= kEPS); } } @@ -664,7 +669,7 @@ TEST(MSGPACK_STL, simple_buffer_string) for (unsigned int k = 0; k < kLoop; k++) { string val1; for (unsigned int i = 0; i < kElements; i++) - val1 += 'a' + rand() % 26; + val1 += static_cast('a' + rand() % 26); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = @@ -681,7 +686,7 @@ TEST(MSGPACK_STL, simple_buffer_cstring) for (unsigned int k = 0; k < kLoop; k++) { string val1; for (unsigned int i = 0; i < kElements; i++) - val1 += 'a' + rand() % 26; + val1 += static_cast('a' + rand() % 26); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1.c_str()); msgpack::object_handle oh = @@ -698,7 +703,7 @@ TEST(MSGPACK_STL, simple_buffer_non_const_cstring) for (unsigned int k = 0; k < kLoop; k++) { string val1; for (unsigned int i = 0; i < kElements; i++) - val1 += 'a' + rand() % 26; + val1 += static_cast('a' + rand() % 26); msgpack::sbuffer sbuf; char* s = new char[val1.size() + 1]; std::memcpy(s, val1.c_str(), val1.size() + 1); diff --git a/test/msgpack_c.cpp b/test/msgpack_c.cpp index cfcfed0c..cb70dfc9 100644 --- a/test/msgpack_c.cpp +++ b/test/msgpack_c.cpp @@ -4,8 +4,13 @@ #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #if defined(_MSC_VER) || defined(__MINGW32__) #define msgpack_rand() ((double)rand() / RAND_MAX) #else // _MSC_VER || __MINGW32__ @@ -26,7 +31,7 @@ const double kEPS = 1e-10; v.push_back(numeric_limits::min()); \ v.push_back(numeric_limits::max()); \ for (unsigned int i = 0; i < kLoop; i++) \ - v.push_back(rand()); \ + v.push_back(static_cast(rand())); \ for (unsigned int i = 0; i < v.size() ; i++) { \ test_type val = v[i]; \ msgpack_sbuffer sbuf; \ @@ -61,7 +66,7 @@ const double kEPS = 1e-10; v.push_back(numeric_limits::min()); \ v.push_back(numeric_limits::max()); \ for (unsigned int i = 0; i < kLoop; i++) \ - v.push_back(rand()); \ + v.push_back(static_cast(rand())); \ for (unsigned int i = 0; i < v.size() ; i++) { \ test_type val = v[i]; \ msgpack_sbuffer sbuf; \ diff --git a/test/msgpack_container.cpp b/test/msgpack_container.cpp index 27212e2f..e2c59609 100644 --- a/test/msgpack_container.cpp +++ b/test/msgpack_container.cpp @@ -12,8 +12,13 @@ #include "test_allocator.hpp" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -75,7 +80,7 @@ TEST(MSGPACK_STL, simple_buffer_vector_char) for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) - val1.push_back(rand()); + val1.push_back(static_cast(rand())); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = @@ -107,7 +112,7 @@ TEST(MSGPACK_STL, simple_buffer_vector_unsigned_char) for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) - val1.push_back(rand()); + val1.push_back(static_cast(rand())); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = @@ -140,7 +145,7 @@ TEST(MSGPACK_STL, simple_buffer_vector_uint8_t) for (unsigned int k = 0; k < kLoop; k++) { type val1; for (unsigned int i = 0; i < kElements; i++) - val1.push_back(rand()); + val1.push_back(static_cast(rand())); msgpack::sbuffer sbuf; msgpack::pack(sbuf, val1); msgpack::object_handle oh = diff --git a/test/msgpack_cpp11.cpp b/test/msgpack_cpp11.cpp index b9ce77bd..c115c481 100644 --- a/test/msgpack_cpp11.cpp +++ b/test/msgpack_cpp11.cpp @@ -1,7 +1,12 @@ #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/test/msgpack_cpp17.cpp b/test/msgpack_cpp17.cpp index fe4649c9..9b596f58 100644 --- a/test/msgpack_cpp17.cpp +++ b/test/msgpack_cpp17.cpp @@ -1,7 +1,12 @@ #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/test/msgpack_stream.cpp b/test/msgpack_stream.cpp index 0a666f2d..4369b50c 100644 --- a/test/msgpack_stream.cpp +++ b/test/msgpack_stream.cpp @@ -9,8 +9,13 @@ #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -26,8 +31,8 @@ const unsigned int kLoop = 1000; msgpack::packer pk(sbuf); \ typedef std::vector vec_type; \ vec_type vec; \ - for(unsigned int i = 0; i < rand() % kLoop; ++i) { \ - vec_type::value_type r = rand(); \ + for(unsigned int i = 0; i < static_cast(rand()) % kLoop; ++i) { \ + vec_type::value_type r = static_cast(rand()); \ vec.push_back(r); \ pk.pack(r); \ } \ @@ -36,7 +41,7 @@ const unsigned int kLoop = 1000; const char *p = sbuf.data(); \ const char * const pend = p + sbuf.size(); \ while (p < pend) { \ - const size_t sz = std::min(pend - p, rand() % 128); \ + const size_t sz = std::min(static_cast(pend - p), static_cast(rand() % 128)); \ pac.reserve_buffer(sz); \ memcpy(pac.buffer(), p, sz); \ pac.buffer_consumed(sz); \ diff --git a/test/msgpack_tuple.cpp b/test/msgpack_tuple.cpp index f68dcf28..e7113648 100644 --- a/test/msgpack_tuple.cpp +++ b/test/msgpack_tuple.cpp @@ -1,6 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + TEST(msgpack_tuple, member_get) { diff --git a/test/msgpack_vref.cpp b/test/msgpack_vref.cpp index dfd00e01..20fb0622 100644 --- a/test/msgpack_vref.cpp +++ b/test/msgpack_vref.cpp @@ -9,8 +9,13 @@ #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/test/msgpack_x3_parse.cpp b/test/msgpack_x3_parse.cpp index 40f61d31..3dbd900e 100644 --- a/test/msgpack_x3_parse.cpp +++ b/test/msgpack_x3_parse.cpp @@ -4,8 +4,13 @@ #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + // To avoid link error TEST(MSGPACK_X3_PARSE, dummy) { @@ -169,7 +174,7 @@ TEST(MSGPACK_X3_PARSE, uint64_2) TEST(MSGPACK_X3_PARSE, int8_1) { - int8_t v = 0b11011111; + int8_t v = static_cast(0b11011111); std::stringstream ss; msgpack::pack(ss, v); @@ -179,7 +184,7 @@ TEST(MSGPACK_X3_PARSE, int8_1) TEST(MSGPACK_X3_PARSE, int8_2) { - int8_t v = 0b10000000; + int8_t v = static_cast(0b10000000); std::stringstream ss; msgpack::pack(ss, v); @@ -189,7 +194,7 @@ TEST(MSGPACK_X3_PARSE, int8_2) TEST(MSGPACK_X3_PARSE, int16_1) { - int16_t v = 0xff00; + int16_t v = static_cast(0xff00); std::stringstream ss; msgpack::pack(ss, v); @@ -199,7 +204,7 @@ TEST(MSGPACK_X3_PARSE, int16_1) TEST(MSGPACK_X3_PARSE, int16_2) { - int16_t v = 0x8000; + int16_t v = static_cast(0x8000); std::stringstream ss; msgpack::pack(ss, v); @@ -209,7 +214,7 @@ TEST(MSGPACK_X3_PARSE, int16_2) TEST(MSGPACK_X3_PARSE, int32_1) { - int32_t v = 0xff000000L; + int32_t v = static_cast(0xff000000L); std::stringstream ss; msgpack::pack(ss, v); @@ -219,7 +224,7 @@ TEST(MSGPACK_X3_PARSE, int32_1) TEST(MSGPACK_X3_PARSE, int32_2) { - int32_t v = 0x80000000L; + int32_t v = static_cast(0x80000000L); std::stringstream ss; msgpack::pack(ss, v); @@ -229,7 +234,7 @@ TEST(MSGPACK_X3_PARSE, int32_2) TEST(MSGPACK_X3_PARSE, int64_1) { - int64_t v = 0xff00000000000000LL; + int64_t v = static_cast(0xff00000000000000LL); std::stringstream ss; msgpack::pack(ss, v); @@ -239,7 +244,7 @@ TEST(MSGPACK_X3_PARSE, int64_1) TEST(MSGPACK_X3_PARSE, int64_2) { - int64_t v = 0x8000000000000000LL; + int64_t v = static_cast(0x8000000000000000LL); std::stringstream ss; msgpack::pack(ss, v); @@ -445,7 +450,7 @@ TEST(MSGPACK_X3_PARSE, string_2) { std::string v; - for (uint64_t i = 0; i != 0x1fU; ++i) v.push_back('0'+(i%10)); + for (uint64_t i = 0; i != 0x1fU; ++i) v.push_back(static_cast('0'+(i%10))); std::stringstream ss; msgpack::pack(ss, v); @@ -458,7 +463,7 @@ TEST(MSGPACK_X3_PARSE, string_3) { std::string v; - for (uint64_t i = 0; i != 0xffU; ++i) v.push_back('0'+(i%10)); + for (uint64_t i = 0; i != 0xffU; ++i) v.push_back(static_cast('0'+(i%10))); std::stringstream ss; msgpack::pack(ss, v); @@ -471,7 +476,7 @@ TEST(MSGPACK_X3_PARSE, string_4) { std::string v; - for (uint64_t i = 0; i != 0xffU+1U; ++i) v.push_back('0'+(i%10)); + for (uint64_t i = 0; i != 0xffU+1U; ++i) v.push_back(static_cast('0'+(i%10))); std::stringstream ss; msgpack::pack(ss, v); @@ -484,7 +489,7 @@ TEST(MSGPACK_X3_PARSE, string_5) { std::string v; - for (uint64_t i = 0; i != 0xffffU; ++i) v.push_back('0'+(i%10)); + for (uint64_t i = 0; i != 0xffffU; ++i) v.push_back(static_cast('0'+(i%10))); std::stringstream ss; msgpack::pack(ss, v); @@ -497,7 +502,7 @@ TEST(MSGPACK_X3_PARSE, string_6) { std::string v; - for (uint64_t i = 0; i != 0xffffUL + 1UL; ++i) v.push_back('0'+(i%10)); + for (uint64_t i = 0; i != 0xffffUL + 1UL; ++i) v.push_back(static_cast('0'+(i%10))); std::stringstream ss; msgpack::pack(ss, v); @@ -520,7 +525,7 @@ TEST(MSGPACK_X3_PARSE, bin_2) { std::vector v; - for (uint64_t i = 0; i != 0x1fU; ++i) v.push_back(i%0xff); + for (uint64_t i = 0; i != 0x1fU; ++i) v.push_back(static_cast(i%0xff)); std::stringstream ss; msgpack::pack(ss, v); @@ -533,7 +538,7 @@ TEST(MSGPACK_X3_PARSE, bin_3) { std::vector v; - for (uint64_t i = 0; i != 0xffU; ++i) v.push_back(i%0xff); + for (uint64_t i = 0; i != 0xffU; ++i) v.push_back(static_cast(i%0xff)); std::stringstream ss; msgpack::pack(ss, v); @@ -546,7 +551,7 @@ TEST(MSGPACK_X3_PARSE, bin_4) { std::vector v; - for (uint64_t i = 0; i != 0xffU+1U; ++i) v.push_back(i%0xff); + for (uint64_t i = 0; i != 0xffU+1U; ++i) v.push_back(static_cast(i%0xff)); std::stringstream ss; msgpack::pack(ss, v); @@ -559,7 +564,7 @@ TEST(MSGPACK_X3_PARSE, bin_5) { std::vector v; - for (uint64_t i = 0; i != 0xffffU; ++i) v.push_back(i%0xff); + for (uint64_t i = 0; i != 0xffffU; ++i) v.push_back(static_cast(i%0xff)); std::stringstream ss; msgpack::pack(ss, v); @@ -572,7 +577,7 @@ TEST(MSGPACK_X3_PARSE, bin_6) { std::vector v; - for (uint64_t i = 0; i != 0xffffUL + 1UL; ++i) v.push_back(i%0xff); + for (uint64_t i = 0; i != 0xffffUL + 1UL; ++i) v.push_back(static_cast(i%0xff)); std::stringstream ss; msgpack::pack(ss, v); diff --git a/test/object.cpp b/test/object.cpp index abf253ee..9095dab8 100644 --- a/test/object.cpp +++ b/test/object.cpp @@ -1,6 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + enum enum_test { elem diff --git a/test/object_with_zone.cpp b/test/object_with_zone.cpp index f23281c9..df71418f 100644 --- a/test/object_with_zone.cpp +++ b/test/object_with_zone.cpp @@ -1,5 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include + +#pragma GCC diagnostic pop + #include #ifdef HAVE_CONFIG_H @@ -202,7 +209,7 @@ TEST(object_with_zone, vector) vector v1; v1.push_back(1); for (unsigned int i = 1; i < kElements; i++) - v1.push_back(i); + v1.push_back(static_cast(i)); msgpack::zone z; msgpack::object obj(v1, z); EXPECT_TRUE(obj.as >() == v1); @@ -282,7 +289,7 @@ TEST(object_with_zone, list) list v1; v1.push_back(1); for (unsigned int i = 1; i < kElements; i++) - v1.push_back(i); + v1.push_back(static_cast(i)); msgpack::zone z; msgpack::object obj(v1, z); EXPECT_TRUE(obj.as >() == v1); @@ -298,7 +305,7 @@ TEST(object_with_zone, deque) deque v1; v1.push_back(1); for (unsigned int i = 1; i < kElements; i++) - v1.push_back(i); + v1.push_back(static_cast(i)); msgpack::zone z; msgpack::object obj(v1, z); EXPECT_TRUE(obj.as >() == v1); @@ -412,7 +419,7 @@ TEST(object_with_zone, set) for (unsigned int k = 0; k < kLoop; k++) { set v1; for (unsigned int i = 0; i < kElements; i++) - v1.insert(i); + v1.insert(static_cast(i)); msgpack::zone z; msgpack::object obj(v1, z); EXPECT_TRUE(obj.as >() == v1); @@ -872,7 +879,7 @@ TEST(object_with_zone, array_char) test_t v1; v1[0] = 1; for (unsigned int i = 1; i < kElements; i++) - v1[i] = rand(); + v1[i] = static_cast(rand()); msgpack::zone z; msgpack::object obj(v1, z); EXPECT_TRUE(obj.as() == v1); @@ -888,7 +895,7 @@ TEST(object_without_zone, array_char) test_t v1; v1[0] = 1; for (unsigned int i = 1; i < kElements; i++) - v1[i] = rand(); + v1[i] = static_cast(rand()); msgpack::object obj(v1); EXPECT_TRUE(obj.as() == v1); v1.front() = 42; @@ -905,7 +912,7 @@ TEST(object_with_zone, array_unsigned_char) test_t v1; v1[0] = 1; for (unsigned int i = 1; i < kElements; i++) - v1[i] = rand(); + v1[i] = static_cast(rand()); msgpack::zone z; msgpack::object obj(v1, z); EXPECT_TRUE(obj.as() == v1); @@ -922,7 +929,7 @@ TEST(object_without_zone, array_unsigned_char) test_t v1; v1[0] = 1; for (unsigned int i = 1; i < kElements; i++) - v1[i] = rand(); + v1[i] = static_cast(rand()); msgpack::object obj(v1); EXPECT_TRUE(obj.as() == v1); v1.front() = 42; @@ -937,7 +944,7 @@ TEST(object_with_zone, forward_list) for (unsigned int k = 0; k < kLoop; k++) { forward_list v1; for (unsigned int i = 0; i < kElements; i++) - v1.push_front(i); + v1.push_front(static_cast(i)); msgpack::zone z; msgpack::object obj(v1, z); EXPECT_TRUE(obj.as >() == v1); @@ -1042,7 +1049,7 @@ TEST(object_with_zone, ext_empty) TEST(object_with_zone, ext) { msgpack::type::ext v(42, 10); - for (int i = 0; i < 10; ++i) v.data()[i] = i; + for (int i = 0; i < 10; ++i) v.data()[i] = static_cast(i); msgpack::zone z; msgpack::object obj(v, z); EXPECT_TRUE(obj.as() == v); diff --git a/test/pack_unpack.cpp b/test/pack_unpack.cpp index a8355816..f29e2001 100644 --- a/test/pack_unpack.cpp +++ b/test/pack_unpack.cpp @@ -1,5 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include + +#pragma GCC diagnostic pop + #include TEST(pack, num) @@ -517,7 +524,7 @@ TEST(unpack, int_off_larger_than_length) TEST(unpack, empty_array_fix) { std::string buf; - buf.push_back(static_cast(0x90)); + buf.push_back(static_cast(0x90)); std::size_t off = 0; msgpack::object_handle oh = msgpack::unpack(buf.data(), buf.size(), off); @@ -529,9 +536,9 @@ TEST(unpack, empty_array_fix) TEST(unpack, empty_array_16) { std::string buf; - buf.push_back(static_cast(0xdc)); - buf.push_back(static_cast(0x00)); - buf.push_back(static_cast(0x00)); + buf.push_back(static_cast(0xdc)); + buf.push_back(static_cast(0x00)); + buf.push_back(static_cast(0x00)); std::size_t off = 0; msgpack::object_handle oh = msgpack::unpack(buf.data(), buf.size(), off); @@ -543,11 +550,11 @@ TEST(unpack, empty_array_16) TEST(unpack, empty_array_32) { std::string buf; - buf.push_back(static_cast(0xdd)); - buf.push_back(static_cast(0x00)); - buf.push_back(static_cast(0x00)); - buf.push_back(static_cast(0x00)); - buf.push_back(static_cast(0x00)); + buf.push_back(static_cast(0xdd)); + buf.push_back(static_cast(0x00)); + buf.push_back(static_cast(0x00)); + buf.push_back(static_cast(0x00)); + buf.push_back(static_cast(0x00)); std::size_t off = 0; msgpack::object_handle oh = msgpack::unpack(buf.data(), buf.size(), off); @@ -559,7 +566,7 @@ TEST(unpack, empty_array_32) TEST(unpack, empty_map_fix) { std::string buf; - buf.push_back(static_cast(0x80)); + buf.push_back(static_cast(0x80)); std::size_t off = 0; msgpack::object_handle oh = msgpack::unpack(buf.data(), buf.size(), off); @@ -571,9 +578,9 @@ TEST(unpack, empty_map_fix) TEST(unpack, empty_map_16) { std::string buf; - buf.push_back(static_cast(0xde)); - buf.push_back(static_cast(0x00)); - buf.push_back(static_cast(0x00)); + buf.push_back(static_cast(0xde)); + buf.push_back(static_cast(0x00)); + buf.push_back(static_cast(0x00)); std::size_t off = 0; msgpack::object_handle oh = msgpack::unpack(buf.data(), buf.size(), off); @@ -585,11 +592,11 @@ TEST(unpack, empty_map_16) TEST(unpack, empty_map_32) { std::string buf; - buf.push_back(static_cast(0xdf)); - buf.push_back(static_cast(0x00)); - buf.push_back(static_cast(0x00)); - buf.push_back(static_cast(0x00)); - buf.push_back(static_cast(0x00)); + buf.push_back(static_cast(0xdf)); + buf.push_back(static_cast(0x00)); + buf.push_back(static_cast(0x00)); + buf.push_back(static_cast(0x00)); + buf.push_back(static_cast(0x00)); std::size_t off = 0; msgpack::object_handle oh = msgpack::unpack(buf.data(), buf.size(), off); diff --git a/test/pack_unpack_c.cpp b/test/pack_unpack_c.cpp index 234216fb..8c35f991 100644 --- a/test/pack_unpack_c.cpp +++ b/test/pack_unpack_c.cpp @@ -1,5 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include + +#pragma GCC diagnostic pop + #include TEST(pack, num) diff --git a/test/raw.cpp b/test/raw.cpp index 17b4166e..f3da1fcc 100644 --- a/test/raw.cpp +++ b/test/raw.cpp @@ -3,8 +3,13 @@ #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -13,7 +18,7 @@ TEST(MSGPACK_RAW_REF, pack_unpack) { std::string s = "ABC"; - msgpack::type::raw_ref rr1(s.data(), s.size()); + msgpack::type::raw_ref rr1(s.data(), static_cast(s.size())); std::stringstream ss; msgpack::pack(ss, rr1); std::string packed_str = ss.str(); @@ -33,7 +38,7 @@ TEST(MSGPACK_RAW_REF, pack_unpack_8_l) { std::string s; - msgpack::type::raw_ref rr1(s.data(), s.size()); + msgpack::type::raw_ref rr1(s.data(), static_cast(s.size())); std::stringstream ss; msgpack::pack(ss, rr1); std::string packed_str = ss.str(); @@ -50,7 +55,7 @@ TEST(MSGPACK_RAW_REF, pack_unpack_8_h) { std::string s(0xff, 'A'); - msgpack::type::raw_ref rr1(s.data(), s.size()); + msgpack::type::raw_ref rr1(s.data(), static_cast(s.size())); std::stringstream ss; msgpack::pack(ss, rr1); std::string packed_str = ss.str(); @@ -68,7 +73,7 @@ TEST(MSGPACK_RAW_REF, pack_unpack_16_l) { std::string s(0xff+1, 'A'); - msgpack::type::raw_ref rr1(s.data(), s.size()); + msgpack::type::raw_ref rr1(s.data(), static_cast(s.size())); std::stringstream ss; msgpack::pack(ss, rr1); std::string packed_str = ss.str(); @@ -87,7 +92,7 @@ TEST(MSGPACK_RAW_REF, pack_unpack_16_h) { std::string s(0xffff, 'A'); - msgpack::type::raw_ref rr1(s.data(), s.size()); + msgpack::type::raw_ref rr1(s.data(), static_cast(s.size())); std::stringstream ss; msgpack::pack(ss, rr1); std::string packed_str = ss.str(); @@ -106,7 +111,7 @@ TEST(MSGPACK_RAW_REF, pack_unpack_32_l) { std::string s(0xffff+1, 'A'); - msgpack::type::raw_ref rr1(s.data(), s.size()); + msgpack::type::raw_ref rr1(s.data(), static_cast(s.size())); std::stringstream ss; msgpack::pack(ss, rr1); std::string packed_str = ss.str(); @@ -127,7 +132,7 @@ TEST(MSGPACK_V4RAW_REF, pack_unpack) { std::string s = "ABC"; - msgpack::type::v4raw_ref rr1(s.data(), s.size()); + msgpack::type::v4raw_ref rr1(s.data(), static_cast(s.size())); std::stringstream ss; msgpack::pack(ss, rr1); std::string packed_str = ss.str(); @@ -146,7 +151,7 @@ TEST(MSGPACK_V4RAW_REF, pack_unpack_fix_l) { std::string s; - msgpack::type::v4raw_ref rr1(s.data(), s.size()); + msgpack::type::v4raw_ref rr1(s.data(), static_cast(s.size())); std::stringstream ss; msgpack::pack(ss, rr1); std::string packed_str = ss.str(); @@ -162,7 +167,7 @@ TEST(MSGPACK_V4RAW_REF, pack_unpack_fix_h) { std::string s(0x1f, 'A'); - msgpack::type::v4raw_ref rr1(s.data(), s.size()); + msgpack::type::v4raw_ref rr1(s.data(), static_cast(s.size())); std::stringstream ss; msgpack::pack(ss, rr1); std::string packed_str = ss.str(); @@ -179,7 +184,7 @@ TEST(MSGPACK_V4RAW_REF, pack_unpack_16_l) { std::string s(0x1f+1, 'A'); - msgpack::type::v4raw_ref rr1(s.data(), s.size()); + msgpack::type::v4raw_ref rr1(s.data(), static_cast(s.size())); std::stringstream ss; msgpack::pack(ss, rr1); std::string packed_str = ss.str(); @@ -198,7 +203,7 @@ TEST(MSGPACK_V4RAW_REF, pack_unpack_16_h) { std::string s(0xffff, 'A'); - msgpack::type::v4raw_ref rr1(s.data(), s.size()); + msgpack::type::v4raw_ref rr1(s.data(), static_cast(s.size())); std::stringstream ss; msgpack::pack(ss, rr1); std::string packed_str = ss.str(); @@ -217,7 +222,7 @@ TEST(MSGPACK_V4RAW_REF, pack_unpack_32_l) { std::string s(0xffff+1, 'A'); - msgpack::type::v4raw_ref rr1(s.data(), s.size()); + msgpack::type::v4raw_ref rr1(s.data(), static_cast(s.size())); std::stringstream ss; msgpack::pack(ss, rr1); std::string packed_str = ss.str(); diff --git a/test/reference.cpp b/test/reference.cpp index 2bbd8fa0..77f67aa8 100644 --- a/test/reference.cpp +++ b/test/reference.cpp @@ -1,6 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + TEST(reference, unpack_int) { msgpack::sbuffer sbuf; diff --git a/test/reference_cpp11.cpp b/test/reference_cpp11.cpp index 531f4fa8..995065de 100644 --- a/test/reference_cpp11.cpp +++ b/test/reference_cpp11.cpp @@ -1,6 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #if !defined(MSGPACK_USE_CPP03) TEST(reference, unpack_int) diff --git a/test/reference_wrapper_cpp11.cpp b/test/reference_wrapper_cpp11.cpp index 46f32f15..7d08db31 100644 --- a/test/reference_wrapper_cpp11.cpp +++ b/test/reference_wrapper_cpp11.cpp @@ -1,7 +1,13 @@ #include #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/test/shared_ptr_cpp11.cpp b/test/shared_ptr_cpp11.cpp index 409ce2cd..8f69d99f 100644 --- a/test/shared_ptr_cpp11.cpp +++ b/test/shared_ptr_cpp11.cpp @@ -1,8 +1,14 @@ #include #include #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/test/size_equal_only.cpp b/test/size_equal_only.cpp index dbcedc5f..89e9f1e2 100644 --- a/test/size_equal_only.cpp +++ b/test/size_equal_only.cpp @@ -1,7 +1,13 @@ #include #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + TEST(size_equal_only, array) { std::stringstream ss; diff --git a/test/streaming.cpp b/test/streaming.cpp index 430ee7e0..def6a7e9 100644 --- a/test/streaming.cpp +++ b/test/streaming.cpp @@ -1,5 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include + +#pragma GCC diagnostic pop + #include TEST(streaming, basic) @@ -168,7 +175,7 @@ public: while(true) { pac.reserve_buffer(32*1024); - size_t len = static_cast(input.readsome(pac.buffer(), pac.buffer_capacity())); + size_t len = static_cast(input.readsome(pac.buffer(), static_cast(pac.buffer_capacity()))); if(len == 0) { return; @@ -240,7 +247,7 @@ TEST(streaming, basic_compat) while(count < 3) { pac.reserve_buffer(32*1024); - size_t len = static_cast(input.readsome(pac.buffer(), pac.buffer_capacity())); + size_t len = static_cast(input.readsome(pac.buffer(), static_cast(pac.buffer_capacity()))); pac.buffer_consumed(len); while(pac.execute()) { @@ -276,7 +283,7 @@ public: while(true) { pac.reserve_buffer(32*1024); - size_t len = static_cast(input.readsome(pac.buffer(), pac.buffer_capacity())); + size_t len = static_cast(input.readsome(pac.buffer(), static_cast(pac.buffer_capacity()))); if(len == 0) { return; diff --git a/test/streaming_c.cpp b/test/streaming_c.cpp index 50162afb..f59f15c6 100644 --- a/test/streaming_c.cpp +++ b/test/streaming_c.cpp @@ -1,5 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include + +#pragma GCC diagnostic pop + #include TEST(streaming, basic) diff --git a/test/unique_ptr_cpp11.cpp b/test/unique_ptr_cpp11.cpp index 624c58a2..316e39d1 100644 --- a/test/unique_ptr_cpp11.cpp +++ b/test/unique_ptr_cpp11.cpp @@ -1,8 +1,14 @@ #include #include #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/test/user_class.cpp b/test/user_class.cpp index 37bc09b2..77b2c089 100644 --- a/test/user_class.cpp +++ b/test/user_class.cpp @@ -2,8 +2,13 @@ #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/test/version.cpp b/test/version.cpp index 6bb39018..78c3bfaa 100644 --- a/test/version.cpp +++ b/test/version.cpp @@ -1,6 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + TEST(version, print) { printf("MSGPACK_VERSION : %s\n", MSGPACK_VERSION); diff --git a/test/visitor.cpp b/test/visitor.cpp index 23eecb30..963f3a61 100644 --- a/test/visitor.cpp +++ b/test/visitor.cpp @@ -1,5 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include + +#pragma GCC diagnostic pop + #include // To avoid link error diff --git a/test/zone.cpp b/test/zone.cpp index 8f6d3a81..e0acb5fd 100644 --- a/test/zone.cpp +++ b/test/zone.cpp @@ -1,6 +1,12 @@ #include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + #include +#pragma GCC diagnostic pop + TEST(zone, allocate_align) { msgpack::zone z;