Fixed compiler warnings for cast to bool in generated code.

Change-Id: I7727aeb478feb23d8ef66fd1ba9499b142b3ea7d
Tested: on Linux.
This commit is contained in:
Wouter van Oortmerssen
2015-12-09 12:56:24 -08:00
parent 42b48bd55f
commit 6fba6b6e71
2 changed files with 11 additions and 6 deletions

View File

@@ -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) {