diff --git a/build/VS2010/flatc.vcxproj b/build/VS2010/flatc.vcxproj
index f21425464..d63edc485 100755
--- a/build/VS2010/flatc.vcxproj
+++ b/build/VS2010/flatc.vcxproj
@@ -136,11 +136,12 @@
NotUsing
MultiThreadedDebugDLL
true
- Level3
+ Level4
WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)
Debug
$(IntDir)
../../Debug/flatc.pdb
+ true
WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)
@@ -224,13 +225,14 @@
NotUsing
MultiThreadedDLL
true
- Level3
+ Level4
WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)
Release
$(IntDir)
../../Release/flatc.pdb
+ true
WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)
diff --git a/build/VS2010/flatsamplebinary.vcxproj b/build/VS2010/flatsamplebinary.vcxproj
index 9f34e7f6d..dfa710c1e 100755
--- a/build/VS2010/flatsamplebinary.vcxproj
+++ b/build/VS2010/flatsamplebinary.vcxproj
@@ -136,11 +136,12 @@
NotUsing
MultiThreadedDebugDLL
true
- Level3
+ Level4
WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)
Debug
$(IntDir)
../../Debug/flatsamplebinary.pdb
+ true
WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)
@@ -224,13 +225,14 @@
NotUsing
MultiThreadedDLL
true
- Level3
+ Level4
WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)
Release
$(IntDir)
../../Release/flatsamplebinary.pdb
+ true
WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)
diff --git a/build/VS2010/flatsampletext.vcxproj b/build/VS2010/flatsampletext.vcxproj
index b66c8f6d1..5b81e6df8 100755
--- a/build/VS2010/flatsampletext.vcxproj
+++ b/build/VS2010/flatsampletext.vcxproj
@@ -136,11 +136,12 @@
NotUsing
MultiThreadedDebugDLL
true
- Level3
+ Level4
WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)
Debug
$(IntDir)
../../Debug/flatsampletext.pdb
+ true
WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)
@@ -224,13 +225,14 @@
NotUsing
MultiThreadedDLL
true
- Level3
+ Level4
WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)
Release
$(IntDir)
../../Release/flatsampletext.pdb
+ true
WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)
diff --git a/build/VS2010/flattests.vcxproj b/build/VS2010/flattests.vcxproj
index b6ccd6164..694a81cbe 100755
--- a/build/VS2010/flattests.vcxproj
+++ b/build/VS2010/flattests.vcxproj
@@ -136,11 +136,12 @@
NotUsing
MultiThreadedDebugDLL
true
- Level3
+ Level4
WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)
Debug
$(IntDir)
../../Debug/flattests.pdb
+ true
WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)
@@ -224,13 +225,14 @@
NotUsing
MultiThreadedDLL
true
- Level3
+ EnableAllWarnings
WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)
Release
$(IntDir)
../../Release/flattests.pdb
+ true
WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)
diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h
index 5b3c9f167..4d4397a1f 100644
--- a/include/flatbuffers/flatbuffers.h
+++ b/include/flatbuffers/flatbuffers.h
@@ -632,7 +632,7 @@ class Verifier {
}
return true;
}
-
+
// Verify this whole buffer, starting with root type T.
template bool VerifyBuffer() const {
// Call T::Verify, which must be in the generated code for this type.
diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h
index 79767e197..7976460cf 100644
--- a/include/flatbuffers/idl.h
+++ b/include/flatbuffers/idl.h
@@ -117,11 +117,11 @@ struct Type {
// Represents a parsed scalar value, it's type, and field offset.
struct Value {
- Value() : constant("0"), offset(-1) {}
-
+ Value() : constant("0"), offset(static_cast(
+ ~(static_cast(0U)))) {}
Type type;
std::string constant;
- int offset;
+ voffset_t offset;
};
// Helper class that retains the original order of a set of identifiers and
diff --git a/include/flatbuffers/util.h b/include/flatbuffers/util.h
index 4c596574b..0a3b0510e 100644
--- a/include/flatbuffers/util.h
+++ b/include/flatbuffers/util.h
@@ -32,10 +32,16 @@ template std::string NumToString(T t) {
// to_string() prints different numbers of digits for floats depending on
// platform and isn't available on Android, so we use stringstream
std::stringstream ss;
- if (sizeof(T) > 1) ss << t;
- else ss << static_cast(t); // Avoid char types used as character data.
+ ss << t;
return ss.str();
}
+// Avoid char types used as character data.
+template<> inline std::string NumToString(signed char t) {
+ return NumToString(static_cast(t));
+}
+template<> inline std::string NumToString(unsigned char t) {
+ return NumToString(static_cast(t));
+}
// Convert an integer value to a hexadecimal string.
// The returned string length is the number of nibbles in
diff --git a/samples/monster_generated.h b/samples/monster_generated.h
index 8282a84ab..50011b486 100755
--- a/samples/monster_generated.h
+++ b/samples/monster_generated.h
@@ -1,4 +1,7 @@
-// automatically generated, do not modify
+// automatically generated by the FlatBuffers compiler, do not modify
+
+#ifndef FLATBUFFERS_GENERATED_MONSTER_MYGAME_SAMPLE_H_
+#define FLATBUFFERS_GENERATED_MONSTER_MYGAME_SAMPLE_H_
#include "flatbuffers/flatbuffers.h"
@@ -30,6 +33,8 @@ 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;
@@ -56,6 +61,17 @@ 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) &&
+ VerifyField(verifier, 4) &&
+ VerifyField(verifier, 6) &&
+ VerifyField(verifier, 8) &&
+ VerifyField(verifier, 10) &&
+ verifier.Verify(name()) &&
+ VerifyField(verifier, 14) &&
+ verifier.Verify(inventory()) &&
+ VerifyField(verifier, 16);
+ }
};
struct MonsterBuilder {
@@ -68,6 +84,7 @@ struct MonsterBuilder {
void add_inventory(flatbuffers::Offset> inventory) { fbb_.AddOffset(14, inventory); }
void add_color(int8_t color) { fbb_.AddElement(16, color, 2); }
MonsterBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
+ MonsterBuilder &operator=(const MonsterBuilder &);
flatbuffers::Offset Finish() { return flatbuffers::Offset(fbb_.EndTable(start_, 7)); }
};
@@ -82,7 +99,19 @@ inline flatbuffers::Offset CreateMonster(flatbuffers::FlatBufferBuilder
return builder_.Finish();
}
+bool VerifyAny(const flatbuffers::Verifier &verifier, const void *union_obj, uint8_t type) {
+ switch (type) {
+ case Any_NONE: return true;
+ case Any_Monster: return reinterpret_cast(union_obj)->Verify(verifier);
+ default: return false;
+ }
+}
+
inline const Monster *GetMonster(const void *buf) { return flatbuffers::GetRoot(buf); }
-}; // namespace MyGame
-}; // namespace Sample
+inline bool VerifyMonsterBuffer(const flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer(); }
+
+}; // namespace MyGame
+}; // namespace Sample
+
+#endif // FLATBUFFERS_GENERATED_MONSTER_MYGAME_SAMPLE_H_
diff --git a/samples/sample_binary.cpp b/samples/sample_binary.cpp
index 92c4c58e1..bb6861743 100755
--- a/samples/sample_binary.cpp
+++ b/samples/sample_binary.cpp
@@ -22,7 +22,7 @@ using namespace MyGame::Sample;
// Example how to use FlatBuffers to create and read binary buffers.
-int main(int argc, const char *argv[]) {
+int main(int /*argc*/, const char * /*argv*/[]) {
// Build up a serialized buffer algorithmically:
flatbuffers::FlatBufferBuilder builder;
diff --git a/samples/sample_text.cpp b/samples/sample_text.cpp
index b4d2d2519..a286e6f80 100755
--- a/samples/sample_text.cpp
+++ b/samples/sample_text.cpp
@@ -24,7 +24,7 @@ using namespace MyGame::Sample;
// This is an example of parsing text straight into a buffer and then
// generating flatbuffer (JSON) text from the buffer.
-int main(int argc, const char *argv[]) {
+int main(int /*argc*/, const char * /*argv*/[]) {
// load FlatBuffer schema (.fbs) and JSON from disk
std::string schemafile;
std::string jsonfile;
diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp
index bba15af76..28fb5a88e 100644
--- a/src/idl_gen_cpp.cpp
+++ b/src/idl_gen_cpp.cpp
@@ -135,7 +135,7 @@ static void GenComment(const std::string &dc,
code += " - " + enum_def.name + "_" + enum_def.vals.vec.front()->name;
code += "]; }\n\n";
}
-
+
if (enum_def.is_union) {
// Generate a verifier function for this union that can be called by the
// table verifier functions. It uses a switch case to select a specific
@@ -274,6 +274,8 @@ static void GenTable(StructDef &struct_def, std::string *code_ptr) {
code += " " + struct_def.name;
code += "Builder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) ";
code += "{ start_ = fbb_.StartTable(); }\n";
+ code += " " + struct_def.name + "Builder &operator=(const ";
+ code += struct_def.name + "Builder &);\n";
code += " flatbuffers::Offset<" + struct_def.name;
code += "> Finish() { return flatbuffers::Offset<" + struct_def.name;
code += ">(fbb_.EndTable(start_, ";
diff --git a/src/idl_gen_java.cpp b/src/idl_gen_java.cpp
index 554794fae..979a80a95 100755
--- a/src/idl_gen_java.cpp
+++ b/src/idl_gen_java.cpp
@@ -78,9 +78,12 @@ static void GenComment(const std::string &dc,
static std::string MakeCamel(const std::string &in, bool first = true) {
std::string s;
for (size_t i = 0; i < in.length(); i++) {
- if (!i && first) s += toupper(in[0]);
- else if (in[i] == '_' && i + 1 < in.length()) s += toupper(in[++i]);
- else s += in[i];
+ if (!i && first)
+ s += static_cast(toupper(in[0]));
+ else if (in[i] == '_' && i + 1 < in.length())
+ s += static_cast(toupper(in[++i]));
+ else
+ s += in[i];
}
return s;
}
@@ -373,7 +376,7 @@ static bool SaveClass(const Parser &parser, const Definition &def,
bool GenerateJava(const Parser &parser,
const std::string &path,
- const std::string &file_name) {
+ const std::string & /*file_name*/) {
using namespace java;
for (auto it = parser.enums_.vec.begin();
diff --git a/src/idl_gen_text.cpp b/src/idl_gen_text.cpp
index ca87e1eb8..fb31936f2 100644
--- a/src/idl_gen_text.cpp
+++ b/src/idl_gen_text.cpp
@@ -34,8 +34,9 @@ const char *NewLine(int indent_step) {
// Print (and its template specialization below for pointers) generate text
// for a single FlatBuffer value into JSON format.
// The general case for scalars:
-template void Print(T val, Type type, int indent, int indent_step,
- StructDef * /*union_sd*/, std::string *_text) {
+template void Print(T val, Type /*type*/, int /*indent*/,
+ int /*indent_step*/, StructDef * /*union_sd*/,
+ std::string *_text) {
std::string &text = *_text;
text += NumToString(val);
}
diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp
index fd0cff23b..272818cad 100644
--- a/src/idl_parser.cpp
+++ b/src/idl_parser.cpp
@@ -287,7 +287,7 @@ FieldDef &Parser::AddField(StructDef &struct_def,
// the largest scalar
struct_def.minalign = std::max(struct_def.minalign, alignment);
struct_def.PadLastField(alignment);
- field.value.offset = static_cast(struct_def.bytesize);
+ field.value.offset = static_cast(struct_def.bytesize);
struct_def.bytesize += size;
}
if (struct_def.fields.Add(name, &field))
diff --git a/tests/test.cpp b/tests/test.cpp
index fdb8ba3ba..521af440e 100644
--- a/tests/test.cpp
+++ b/tests/test.cpp
@@ -207,7 +207,8 @@ void ParseAndGenerateTextTest() {
}
template void CompareTableFieldValue(flatbuffers::Table *table,
- int voffset, T val) {
+ flatbuffers::voffset_t voffset,
+ T val) {
T read = table->GetField(voffset, static_cast(0));
TEST_EQ(read, val);
}
@@ -231,7 +232,7 @@ void FuzzTest1() {
const double double_val = 3.14159265359;
const int test_values_max = 11;
- const int fields_per_object = 4;
+ const flatbuffers::voffset_t fields_per_object = 4;
const int num_fuzz_objects = 10000; // The higher, the more thorough :)
flatbuffers::FlatBufferBuilder builder;
@@ -244,9 +245,9 @@ void FuzzTest1() {
// fields_per_object fields, each of a random type.
for (int i = 0; i < num_fuzz_objects; i++) {
auto start = builder.StartTable();
- for (int f = 0; f < fields_per_object; f++) {
+ for (flatbuffers::voffset_t f = 0; f < fields_per_object; f++) {
int choice = lcg_rand() % test_values_max;
- flatbuffers::voffset_t off = flatbuffers::FieldIndexToOffset(f);
+ auto off = flatbuffers::FieldIndexToOffset(f);
switch (choice) {
case 0: builder.AddElement(off, bool_val, 0); break;
case 1: builder.AddElement(off, char_val, 0); break;
@@ -274,7 +275,7 @@ void FuzzTest1() {
// so this is deterministic.
for (int i = 0; i < num_fuzz_objects; i++) {
auto table = reinterpret_cast(eob - objects[i]);
- for (int f = 0; f < fields_per_object; f++) {
+ for (flatbuffers::voffset_t f = 0; f < fields_per_object; f++) {
int choice = lcg_rand() % test_values_max;
flatbuffers::voffset_t off = flatbuffers::FieldIndexToOffset(f);
switch (choice) {
@@ -477,7 +478,7 @@ void ErrorTest() {
TestError("union Z { X } struct X { Y:int; }", "only tables");
}
-int main(int argc, const char *argv[]) {
+int main(int /*argc*/, const char * /*argv*/[]) {
// Run our various test suites:
auto flatbuf = CreateFlatBufferTest();