From bc5fa9d52ffd60b4d027f2acc6160982571b9a9c Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Mon, 25 Aug 2014 10:42:38 -0700 Subject: [PATCH] Fixed compile errors in VS / gcc for recent commits. Tested: on Windows & Linux. Change-Id: I90e18c448fc2fafeb83a6cdc3776174479874562 --- CMakeLists.txt | 8 ++++---- include/flatbuffers/util.h | 4 ++-- samples/monster_generated.h | 24 ++++++++++++++---------- src/idl_gen_text.cpp | 3 ++- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac1c3a6e4..57fdba058 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,13 +52,13 @@ set(CMAKE_BUILD_TYPE Debug) # source_group(Tests FILES ${FlatBuffers_Tests_SRCS}) if(APPLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++") + set(CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ -Wall -pedantic -Werror -Wextra") elseif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") + set(CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra") endif() -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra") - if(FLATBUFFERS_CODE_COVERAGE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage") set(CMAKE_EXE_LINKER_FLAGS diff --git a/include/flatbuffers/util.h b/include/flatbuffers/util.h index 38402154b..93cf0cc52 100644 --- a/include/flatbuffers/util.h +++ b/include/flatbuffers/util.h @@ -138,7 +138,7 @@ inline void EnsureDirExists(const std::string &filepath) { auto parent = StripFileName(filepath); if (parent.length()) EnsureDirExists(parent); #ifdef _WIN32 - _mkdir(filepath.c_str()) + _mkdir(filepath.c_str()); #else mkdir(filepath.c_str(), S_IRWXU|S_IRGRP|S_IXGRP); #endif @@ -154,7 +154,7 @@ inline int ToUTF8(uint32_t ucc, std::string *out) { for (int i = 0; i < 6; i++) { // Max bits this encoding can represent. uint32_t max_bits = 6 + i * 5 + static_cast(!i); - if (ucc < (1 << max_bits)) { // does it fit? + if (ucc < (1u << max_bits)) { // does it fit? // Remaining bits not encoded in the first byte, store 6 bits each uint32_t remain_bits = i * 6; // Store first byte: diff --git a/samples/monster_generated.h b/samples/monster_generated.h index ed4e58366..b2a44e65f 100755 --- a/samples/monster_generated.h +++ b/samples/monster_generated.h @@ -5,9 +5,13 @@ #include "flatbuffers/flatbuffers.h" + namespace MyGame { namespace Sample { +struct Vec3; +struct Monster; + enum { Color_Red = 0, Color_Green = 1, @@ -33,10 +37,7 @@ inline const char **EnumNamesAny() { inline const char *EnumNameAny(int e) { return EnumNamesAny()[e]; } -bool VerifyAny(const flatbuffers::Verifier &verifier, const void *union_obj, uint8_t type); - -struct Vec3; -struct Monster; +bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, uint8_t type); MANUALLY_ALIGNED_STRUCT(4) Vec3 { private: @@ -46,7 +47,7 @@ MANUALLY_ALIGNED_STRUCT(4) Vec3 { public: Vec3(float x, float y, float z) - : x_(flatbuffers::EndianScalar(x)), y_(flatbuffers::EndianScalar(y)), z_(flatbuffers::EndianScalar(z)) {} + : x_(flatbuffers::EndianScalar(x)), y_(flatbuffers::EndianScalar(y)), z_(flatbuffers::EndianScalar(z)) { } float x() const { return flatbuffers::EndianScalar(x_); } float y() const { return flatbuffers::EndianScalar(y_); } @@ -61,8 +62,8 @@ struct Monster : private flatbuffers::Table { const flatbuffers::String *name() const { return GetPointer(10); } const flatbuffers::Vector *inventory() const { return GetPointer *>(14); } int8_t color() const { return GetField(16, 2); } - bool Verify(const flatbuffers::Verifier &verifier) const { - return VerifyTable(verifier) && + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* pos */) && VerifyField(verifier, 6 /* mana */) && VerifyField(verifier, 8 /* hp */) && @@ -70,7 +71,8 @@ struct Monster : private flatbuffers::Table { verifier.Verify(name()) && VerifyField(verifier, 14 /* inventory */) && verifier.Verify(inventory()) && - VerifyField(verifier, 16 /* color */); + VerifyField(verifier, 16 /* color */) && + verifier.EndTable(); } }; @@ -105,7 +107,7 @@ inline flatbuffers::Offset CreateMonster(flatbuffers::FlatBufferBuilder return builder_.Finish(); } -bool VerifyAny(const flatbuffers::Verifier &verifier, const void *union_obj, uint8_t type) { +bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, uint8_t type) { switch (type) { case Any_NONE: return true; case Any_Monster: return verifier.VerifyTable(reinterpret_cast(union_obj)); @@ -115,7 +117,9 @@ bool VerifyAny(const flatbuffers::Verifier &verifier, const void *union_obj, uin inline const Monster *GetMonster(const void *buf) { return flatbuffers::GetRoot(buf); } -inline bool VerifyMonsterBuffer(const flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer(); } +inline bool VerifyMonsterBuffer(flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer(); } + +inline void FinishMonsterBuffer(flatbuffers::FlatBufferBuilder &fbb, flatbuffers::Offset root) { fbb.Finish(root); } } // namespace Sample } // namespace MyGame diff --git a/src/idl_gen_text.cpp b/src/idl_gen_text.cpp index 0fd4674b1..a4e36f825 100644 --- a/src/idl_gen_text.cpp +++ b/src/idl_gen_text.cpp @@ -112,7 +112,8 @@ static void EscapeString(const String &s, std::string *_text) { // Parses as Unicode within JSON's \uXXXX range, so use that. text += "\\u"; text += IntToStringHex(ucc, 4); - i = utf8 - s.c_str() - 1; // Skip past characters recognized. + // Skip past characters recognized. + i = static_cast(utf8 - s.c_str() - 1); } else { // It's either unprintable ASCII, arbitrary binary, or Unicode data // that doesn't fit \uXXXX, so use \xXX escape code instead.