diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index 6bec05afd..34441750f 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -317,7 +317,7 @@ struct EnumVal { struct EnumDef : public Definition { EnumDef() : is_union(false), uses_type_aliases(false) {} - EnumVal *ReverseLookup(int enum_idx, bool skip_union_default = true) { + EnumVal *ReverseLookup(int64_t enum_idx, bool skip_union_default = true) { for (auto it = vals.vec.begin() + static_cast(is_union && skip_union_default); it != vals.vec.end(); ++it) { diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index e497a9bab..15f2f38c2 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -1295,7 +1295,7 @@ class CppGenerator : public BaseGenerator { std::string GetDefaultScalarValue(const FieldDef &field) { if (field.value.type.enum_def && IsScalar(field.value.type.base_type)) { auto ev = field.value.type.enum_def->ReverseLookup( - static_cast(StringToInt(field.value.constant.c_str())), false); + StringToInt(field.value.constant.c_str()), false); if (ev) { return WrapInNameSpace(field.value.type.enum_def->defined_namespace, GetEnumValUse(*field.value.type.enum_def, *ev)); diff --git a/src/idl_gen_js.cpp b/src/idl_gen_js.cpp index 42647cbaf..8c7e713a8 100644 --- a/src/idl_gen_js.cpp +++ b/src/idl_gen_js.cpp @@ -371,7 +371,7 @@ class JsGenerator : public BaseGenerator { std::string GenDefaultValue(const Value &value, const std::string &context) { if (value.type.enum_def) { if (auto val = value.type.enum_def->ReverseLookup( - atoi(value.constant.c_str()), false)) { + StringToInt(value.constant.c_str()), false)) { if (lang_.language == IDLOptions::kTs) { return GenPrefixedTypeName(WrapInNameSpace(*value.type.enum_def), value.type.enum_def->file) + diff --git a/src/idl_gen_php.cpp b/src/idl_gen_php.cpp index 101f3c28f..08250e98c 100644 --- a/src/idl_gen_php.cpp +++ b/src/idl_gen_php.cpp @@ -876,7 +876,7 @@ class PhpGenerator : public BaseGenerator { std::string GenDefaultValue(const Value &value) { if (value.type.enum_def) { if (auto val = value.type.enum_def->ReverseLookup( - atoi(value.constant.c_str()), false)) { + StringToInt(value.constant.c_str()), false)) { return WrapInNameSpace(*value.type.enum_def) + "::" + val->name; } } diff --git a/src/idl_gen_text.cpp b/src/idl_gen_text.cpp index 95165fd04..40afbf40e 100644 --- a/src/idl_gen_text.cpp +++ b/src/idl_gen_text.cpp @@ -51,7 +51,7 @@ bool Print(T val, Type type, int /*indent*/, Type * /*union_type*/, const IDLOptions &opts, std::string *_text) { std::string &text = *_text; if (type.enum_def && opts.output_enum_identifiers) { - auto enum_val = type.enum_def->ReverseLookup(static_cast(val)); + auto enum_val = type.enum_def->ReverseLookup(static_cast(val)); if (enum_val) { text += "\""; text += enum_val->name; diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index 39a96d11f..1a9f8b2e3 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -656,8 +656,8 @@ CheckedError Parser::ParseField(StructDef &struct_def) { if (type.enum_def && !type.enum_def->is_union && !type.enum_def->attributes.Lookup("bit_flags") && - !type.enum_def->ReverseLookup(static_cast( - StringToInt(field->value.constant.c_str())))) { + !type.enum_def->ReverseLookup(StringToInt( + field->value.constant.c_str()))) { return Error("default value of " + field->value.constant + " for field " + name + " is not part of enum " + type.enum_def->name); } @@ -668,8 +668,8 @@ CheckedError Parser::ParseField(StructDef &struct_def) { if (type.enum_def && IsScalar(type.base_type) && !struct_def.fixed && !type.enum_def->attributes.Lookup("bit_flags") && - !type.enum_def->ReverseLookup( - static_cast(StringToInt(field->value.constant.c_str())))) + !type.enum_def->ReverseLookup(StringToInt( + field->value.constant.c_str()))) Warning("enum " + type.enum_def->name + " does not have a declaration for this field\'s default of " + field->value.constant);