From 622b8d05cf69cc26babc6a043d1f7a4153755652 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Mon, 15 Jun 2015 15:57:48 -0700 Subject: [PATCH] Fixed warnings on Windows --- build/VS2010/flattests.vcxproj | 3 ++- include/flatbuffers/reflection.h | 26 ++++++++++++++++---------- src/idl_parser.cpp | 6 ++++-- tests/test.cpp | 9 ++++++++- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/build/VS2010/flattests.vcxproj b/build/VS2010/flattests.vcxproj index 96d76b13a..447eebdf8 100755 --- a/build/VS2010/flattests.vcxproj +++ b/build/VS2010/flattests.vcxproj @@ -265,6 +265,7 @@ + @@ -276,4 +277,4 @@ - + \ No newline at end of file diff --git a/include/flatbuffers/reflection.h b/include/flatbuffers/reflection.h index fd706f120..475257a31 100644 --- a/include/flatbuffers/reflection.h +++ b/include/flatbuffers/reflection.h @@ -48,14 +48,16 @@ inline const Table *GetAnyRoot(const uint8_t *flatbuf) { template T GetFieldI(const Table *table, const reflection::Field *field) { assert(sizeof(T) == GetTypeSize(field->type()->base_type())); - return table->GetField(field->offset(), field->default_integer()); + return table->GetField(field->offset(), + static_cast(field->default_integer())); } // Get a field, if you know it's floating point and its exact type. template T GetFieldF(const Table *table, const reflection::Field *field) { assert(sizeof(T) == GetTypeSize(field->type()->base_type())); - return table->GetField(field->offset(), field->default_real()); + return table->GetField(field->offset(), + static_cast(field->default_real())); } // Get a field, if you know it's a string. @@ -106,7 +108,7 @@ inline double GetAnyFieldF(const Table *table, case reflection::Double: return GetFieldF(table, field); case reflection::String: return strtod(GetFieldS(table, field)->c_str(), nullptr); - default: return GetAnyFieldI(table, field); + default: return static_cast(GetAnyFieldI(table, field)); } } @@ -191,6 +193,7 @@ template class pointer_inside_vector { const T *operator->() const { return operator*(); } + void operator=(const pointer_inside_vector &piv); private: size_t offset_; const std::vector &vec_; @@ -220,7 +223,7 @@ class ResizeContext { if (!delta_) return; // We can't shrink by less than largest_scalar_t. // Now change all the offsets by delta_. auto root = GetAnyRoot(buf_.data()); - Straddle(buf_.data(), root, buf_.data()); + Straddle(buf_.data(), root, buf_.data()); ResizeTable(schema.root_table(), root); // We can now add or remove bytes at start. if (delta_ > 0) buf_.insert(buf_.begin() + start, delta_, 0); @@ -230,8 +233,8 @@ class ResizeContext { // Check if the range between first (lower address) and second straddles // the insertion point. If it does, change the offset at offsetloc (of // type T, with direction D). - template void Straddle(void *first, void *second, - void *offsetloc) { + template void Straddle(void *first, void *second, + void *offsetloc) { if (first <= startptr_ && second >= startptr_) { WriteScalar(offsetloc, ReadScalar(offsetloc) + delta_ * D); DagCheck(offsetloc) = true; @@ -283,7 +286,7 @@ class ResizeContext { if (DagCheck(offsetloc)) continue; // This offset already visited. auto ref = offsetloc + ReadScalar(offsetloc); - Straddle(offsetloc, ref, offsetloc); + Straddle(offsetloc, ref, offsetloc); // Recurse. switch (base_type) { case reflection::Obj: { @@ -301,7 +304,7 @@ class ResizeContext { if (DagCheck(loc)) continue; // This offset already visited. auto dest = loc + vec->Get(i); - Straddle(loc, dest ,loc); + Straddle(loc, dest ,loc); ResizeTable(elemobjectdef, reinterpret_cast(dest)); } break; @@ -325,6 +328,8 @@ class ResizeContext { } } + void operator=(const ResizeContext &rc); + private: const reflection::Schema &schema_; uint8_t *startptr_; @@ -361,7 +366,7 @@ template void ResizeVector(const reflection::Schema &schema, uoffset_t newsize, T val, const Vector *vec, std::vector *flatbuf) { - auto delta_elem = newsize - static_cast(vec->size()); + auto delta_elem = static_cast(newsize) - static_cast(vec->size()); auto delta_bytes = delta_elem * static_cast(sizeof(T)); auto vec_start = reinterpret_cast(vec) - flatbuf->data(); auto start = static_cast(vec_start + sizeof(uoffset_t) + @@ -372,7 +377,8 @@ template void ResizeVector(const reflection::Schema &schema, // Set new elements to "val". for (int i = 0; i < delta_elem; i++) { auto loc = flatbuf->data() + start + i * sizeof(T); - if (std::is_scalar::value) { + auto is_scalar = std::is_scalar::value; + if (is_scalar) { WriteScalar(loc, val); } else { // struct *reinterpret_cast(loc) = val; diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index 9afe968dc..2ed401b77 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -40,7 +40,7 @@ const char kTypeSizes[] = { // The enums in the reflection schema should match the ones we use internally. // Compare the last element to check if these go out of sync. static_assert(BASE_TYPE_UNION == - static_cast(reflection::BaseType::Union), + static_cast(reflection::Union), "enums don't match"); static void Error(const std::string &msg) { @@ -1346,7 +1346,9 @@ Offset StructDef::Serialize(FlatBufferBuilder *builder) const { std::vector> field_offsets; for (auto it = fields.vec.begin(); it != fields.vec.end(); ++it) { - field_offsets.push_back((*it)->Serialize(builder, it - fields.vec.begin())); + field_offsets.push_back( + (*it)->Serialize(builder, + static_cast(it - fields.vec.begin()))); } return reflection::CreateObject(*builder, builder->CreateString(name), diff --git a/tests/test.cpp b/tests/test.cpp index 573d998ed..9020125f8 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#define FLATBUFFERS_DEBUG_VERIFICATION_FAILURE 1 + #include "flatbuffers/flatbuffers.h" #include "flatbuffers/idl.h" #include "flatbuffers/util.h" @@ -292,7 +294,12 @@ void ReflectionTest(uint8_t *flatbuf, size_t length) { // Load a binary schema. std::string bfbsfile; TEST_EQ(flatbuffers::LoadFile( - "tests/monster_test.bfbs", false, &bfbsfile), true); + "tests/monster_test.bfbs", true, &bfbsfile), true); + + // Verify it, just in case: + flatbuffers::Verifier verifier( + reinterpret_cast(bfbsfile.c_str()), bfbsfile.length()); + TEST_EQ(reflection::VerifySchemaBuffer(verifier), true); // Make sure the schema is what we expect it to be. auto schema = reflection::GetSchema(bfbsfile.c_str());