Switched VS build to -W4, and fixed all resulting warnings.

Change-Id: I654217cbd01a3a449503d95753e19b672ec7ec23
Tested: on Windows, Linux
This commit is contained in:
Wouter van Oortmerssen 2014-06-30 15:56:31 -07:00
parent a0b6ffc25b
commit 1256307a38
15 changed files with 83 additions and 33 deletions

View File

@ -136,11 +136,12 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<WarningLevel>Level3</WarningLevel>
<WarningLevel>Level4</WarningLevel>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AssemblerListingLocation>Debug</AssemblerListingLocation>
<ObjectFileName>$(IntDir)</ObjectFileName>
<ProgramDataBaseFileName>../../Debug/flatc.pdb</ProgramDataBaseFileName>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
@ -224,13 +225,14 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<WarningLevel>Level3</WarningLevel>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>
</DebugInformationFormat>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AssemblerListingLocation>Release</AssemblerListingLocation>
<ObjectFileName>$(IntDir)</ObjectFileName>
<ProgramDataBaseFileName>../../Release/flatc.pdb</ProgramDataBaseFileName>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)</PreprocessorDefinitions>

View File

@ -136,11 +136,12 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<WarningLevel>Level3</WarningLevel>
<WarningLevel>Level4</WarningLevel>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AssemblerListingLocation>Debug</AssemblerListingLocation>
<ObjectFileName>$(IntDir)</ObjectFileName>
<ProgramDataBaseFileName>../../Debug/flatsamplebinary.pdb</ProgramDataBaseFileName>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
@ -224,13 +225,14 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<WarningLevel>Level3</WarningLevel>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>
</DebugInformationFormat>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AssemblerListingLocation>Release</AssemblerListingLocation>
<ObjectFileName>$(IntDir)</ObjectFileName>
<ProgramDataBaseFileName>../../Release/flatsamplebinary.pdb</ProgramDataBaseFileName>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)</PreprocessorDefinitions>

View File

@ -136,11 +136,12 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<WarningLevel>Level3</WarningLevel>
<WarningLevel>Level4</WarningLevel>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AssemblerListingLocation>Debug</AssemblerListingLocation>
<ObjectFileName>$(IntDir)</ObjectFileName>
<ProgramDataBaseFileName>../../Debug/flatsampletext.pdb</ProgramDataBaseFileName>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
@ -224,13 +225,14 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<WarningLevel>Level3</WarningLevel>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>
</DebugInformationFormat>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AssemblerListingLocation>Release</AssemblerListingLocation>
<ObjectFileName>$(IntDir)</ObjectFileName>
<ProgramDataBaseFileName>../../Release/flatsampletext.pdb</ProgramDataBaseFileName>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)</PreprocessorDefinitions>

View File

@ -136,11 +136,12 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<WarningLevel>Level3</WarningLevel>
<WarningLevel>Level4</WarningLevel>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AssemblerListingLocation>Debug</AssemblerListingLocation>
<ObjectFileName>$(IntDir)</ObjectFileName>
<ProgramDataBaseFileName>../../Debug/flattests.pdb</ProgramDataBaseFileName>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
@ -224,13 +225,14 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<WarningLevel>Level3</WarningLevel>
<WarningLevel>EnableAllWarnings</WarningLevel>
<DebugInformationFormat>
</DebugInformationFormat>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AssemblerListingLocation>Release</AssemblerListingLocation>
<ObjectFileName>$(IntDir)</ObjectFileName>
<ProgramDataBaseFileName>../../Release/flattests.pdb</ProgramDataBaseFileName>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)</PreprocessorDefinitions>

View File

@ -632,7 +632,7 @@ class Verifier {
}
return true;
}
// Verify this whole buffer, starting with root type T.
template<typename T> bool VerifyBuffer() const {
// Call T::Verify, which must be in the generated code for this type.

View File

@ -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<voffset_t>(
~(static_cast<voffset_t>(0U)))) {}
Type type;
std::string constant;
int offset;
voffset_t offset;
};
// Helper class that retains the original order of a set of identifiers and

View File

@ -32,10 +32,16 @@ template<typename T> 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<int>(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>(signed char t) {
return NumToString(static_cast<int>(t));
}
template<> inline std::string NumToString<unsigned char>(unsigned char t) {
return NumToString(static_cast<int>(t));
}
// Convert an integer value to a hexadecimal string.
// The returned string length is the number of nibbles in

View File

@ -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<const flatbuffers::String *>(10); }
const flatbuffers::Vector<uint8_t> *inventory() const { return GetPointer<const flatbuffers::Vector<uint8_t> *>(14); }
int8_t color() const { return GetField<int8_t>(16, 2); }
bool Verify(const flatbuffers::Verifier &verifier) const {
return VerifyTable(verifier) &&
VerifyField<Vec3>(verifier, 4) &&
VerifyField<int16_t>(verifier, 6) &&
VerifyField<int16_t>(verifier, 8) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 10) &&
verifier.Verify(name()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 14) &&
verifier.Verify(inventory()) &&
VerifyField<int8_t>(verifier, 16);
}
};
struct MonsterBuilder {
@ -68,6 +84,7 @@ struct MonsterBuilder {
void add_inventory(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> inventory) { fbb_.AddOffset(14, inventory); }
void add_color(int8_t color) { fbb_.AddElement<int8_t>(16, color, 2); }
MonsterBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
MonsterBuilder &operator=(const MonsterBuilder &);
flatbuffers::Offset<Monster> Finish() { return flatbuffers::Offset<Monster>(fbb_.EndTable(start_, 7)); }
};
@ -82,7 +99,19 @@ inline flatbuffers::Offset<Monster> 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<const Monster *>(union_obj)->Verify(verifier);
default: return false;
}
}
inline const Monster *GetMonster(const void *buf) { return flatbuffers::GetRoot<Monster>(buf); }
}; // namespace MyGame
}; // namespace Sample
inline bool VerifyMonsterBuffer(const flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer<Monster>(); }
}; // namespace MyGame
}; // namespace Sample
#endif // FLATBUFFERS_GENERATED_MONSTER_MYGAME_SAMPLE_H_

View File

@ -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;

View File

@ -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;

View File

@ -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_, ";

View File

@ -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<char>(toupper(in[0]));
else if (in[i] == '_' && i + 1 < in.length())
s += static_cast<char>(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();

View File

@ -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<typename T> void Print(T val, Type type, int indent, int indent_step,
StructDef * /*union_sd*/, std::string *_text) {
template<typename T> void Print(T val, Type /*type*/, int /*indent*/,
int /*indent_step*/, StructDef * /*union_sd*/,
std::string *_text) {
std::string &text = *_text;
text += NumToString(val);
}

View File

@ -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<uoffset_t>(struct_def.bytesize);
field.value.offset = static_cast<voffset_t>(struct_def.bytesize);
struct_def.bytesize += size;
}
if (struct_def.fields.Add(name, &field))

View File

@ -207,7 +207,8 @@ void ParseAndGenerateTextTest() {
}
template<typename T> void CompareTableFieldValue(flatbuffers::Table *table,
int voffset, T val) {
flatbuffers::voffset_t voffset,
T val) {
T read = table->GetField(voffset, static_cast<T>(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<uint8_t >(off, bool_val, 0); break;
case 1: builder.AddElement<int8_t >(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<flatbuffers::Table *>(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();