mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
Fixed compiler warnings for cast to bool in generated code.
Change-Id: I7727aeb478feb23d8ef66fd1ba9499b142b3ea7d Tested: on Linux.
This commit is contained in:
@@ -234,11 +234,16 @@ static void GenEnum(const Parser &parser, EnumDef &enum_def,
|
||||
// underlying type to the interface type.
|
||||
std::string GenUnderlyingCast(const Parser &parser, const FieldDef &field,
|
||||
bool from, const std::string &val) {
|
||||
return (field.value.type.enum_def && IsScalar(field.value.type.base_type)) ||
|
||||
field.value.type.base_type == BASE_TYPE_BOOL
|
||||
? "static_cast<" + GenTypeBasic(parser, field.value.type, from) + ">(" +
|
||||
val + ")"
|
||||
: val;
|
||||
if (from && field.value.type.base_type == BASE_TYPE_BOOL) {
|
||||
return val + " != 0";
|
||||
} else if ((field.value.type.enum_def &&
|
||||
IsScalar(field.value.type.base_type)) ||
|
||||
field.value.type.base_type == BASE_TYPE_BOOL) {
|
||||
return "static_cast<" + GenTypeBasic(parser, field.value.type, from) +
|
||||
">(" + val + ")";
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
std::string GenFieldOffsetName(const FieldDef &field) {
|
||||
|
||||
@@ -236,7 +236,7 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
const MyGame::Example::Monster *testnestedflatbuffer_nested_root() const { return flatbuffers::GetRoot<MyGame::Example::Monster>(testnestedflatbuffer()->Data()); }
|
||||
const Stat *testempty() const { return GetPointer<const Stat *>(VT_TESTEMPTY); }
|
||||
Stat *mutable_testempty() { return GetPointer<Stat *>(VT_TESTEMPTY); }
|
||||
bool testbool() const { return static_cast<bool>(GetField<uint8_t>(VT_TESTBOOL, 0)); }
|
||||
bool testbool() const { return GetField<uint8_t>(VT_TESTBOOL, 0) != 0; }
|
||||
bool mutate_testbool(bool _testbool) { return SetField(VT_TESTBOOL, static_cast<uint8_t>(_testbool)); }
|
||||
int32_t testhashs32_fnv1() const { return GetField<int32_t>(VT_TESTHASHS32_FNV1, 0); }
|
||||
bool mutate_testhashs32_fnv1(int32_t _testhashs32_fnv1) { return SetField(VT_TESTHASHS32_FNV1, _testhashs32_fnv1); }
|
||||
|
||||
Reference in New Issue
Block a user