From c57ab92e60cd842d6dd71f7390f4c3eed05a9247 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Wed, 8 Feb 2017 15:38:18 -0800 Subject: [PATCH] Fixes for Windows compiler errors. Change-Id: I909ea6866089f36f9cb79d435bbecd29623fd8f7 --- include/flatbuffers/flexbuffers.h | 14 ++++++++------ tests/test.cpp | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/flatbuffers/flexbuffers.h b/include/flatbuffers/flexbuffers.h index 7f7810fd5..d588fa40f 100644 --- a/include/flatbuffers/flexbuffers.h +++ b/include/flatbuffers/flexbuffers.h @@ -141,8 +141,8 @@ inline uint64_t ReadUInt64(const uint8_t *data, uint8_t byte_width) { // the conditionals in ReadSizedScalar. Can also use inline asm. #ifdef _MSC_VER uint64_t u = 0; - __movsb(reinterpret_cast(&u), - reinterpret_cast(data), byte_width); + __movsb(reinterpret_cast(&u), + reinterpret_cast(data), byte_width); return flatbuffers::EndianScalar(u); #else return ReadSizedScalar( @@ -307,7 +307,8 @@ class Map : public Vector { const size_t num_prefixed_fields = 3; auto keys_offset = data_ - byte_width_ * num_prefixed_fields; return TypedVector(Indirect(keys_offset, byte_width_), - ReadUInt64(keys_offset + byte_width_, byte_width_), + static_cast( + ReadUInt64(keys_offset + byte_width_, byte_width_)), TYPE_KEY); } @@ -878,7 +879,7 @@ class Builder FLATBUFFERS_FINAL_CLASS { // Remove temp elements and return vector. stack_.resize(start); stack_.push_back(vec); - return vec.u_; + return static_cast(vec.u_); } size_t EndMap(size_t start) { @@ -904,7 +905,8 @@ class Builder FLATBUFFERS_FINAL_CLASS { // sorted fashion. // std::sort is typically already a lot faster on sorted data though. auto dict = reinterpret_cast(stack_.data() + start); - std::sort(dict, dict + len, [&](const TwoValue &a, const TwoValue &b) { + std::sort(dict, dict + len, + [&](const TwoValue &a, const TwoValue &b) -> bool { auto as = reinterpret_cast(buf_.data() + a.key.u_); auto bs = reinterpret_cast(buf_.data() + b.key.u_); auto comp = strcmp(as, bs); @@ -921,7 +923,7 @@ class Builder FLATBUFFERS_FINAL_CLASS { // Remove temp elements and return map. stack_.resize(start); stack_.push_back(vec); - return vec.u_; + return static_cast(vec.u_); } template size_t Vector(F f) { diff --git a/tests/test.cpp b/tests/test.cpp index 8ffb2c117..106a47921 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -1372,9 +1372,9 @@ void FlexBuffersTest() { slb += "Fred"; slb.IndirectFloat(4.0f); }); - std::vector ints = { 1, 2, 3 }; + int ints[] = { 1, 2, 3 }; slb.Add("bar", ints); - slb.FixedTypedVector("bar3", ints.data(), ints.size()); // Static size. + slb.FixedTypedVector("bar3", ints, sizeof(ints) / sizeof(int)); slb.Double("foo", 100); slb.Map("mymap", [&]() { slb.String("foo", "Fred"); // Testing key and string reuse.