From feb481661094db2a73912f8e2d32bac9473ca47f Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Fri, 25 Sep 2015 09:21:31 -0700 Subject: [PATCH] Fixed .proto translation making scalars into required fields. Change-Id: If414d156b4e9bc7fead5f131823b2c419cdc4e2c Tested: on Linux. --- samples/monster_generated.h | 4 ++-- src/idl_parser.cpp | 2 +- tests/monster_test_generated.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/monster_generated.h b/samples/monster_generated.h index b761d6f..878a768 100644 --- a/samples/monster_generated.h +++ b/samples/monster_generated.h @@ -23,7 +23,7 @@ inline const char **EnumNamesColor() { return names; } -inline const char *EnumNameColor(Color e) { return EnumNamesColor()[e]; } +inline const char *EnumNameColor(Color e) { return EnumNamesColor()[static_cast(e)]; } enum Any { Any_NONE = 0, @@ -35,7 +35,7 @@ inline const char **EnumNamesAny() { return names; } -inline const char *EnumNameAny(Any e) { return EnumNamesAny()[e]; } +inline const char *EnumNameAny(Any e) { return EnumNamesAny()[static_cast(e)]; } inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, Any type); diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index 077320b..d5aa312 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -1080,7 +1080,7 @@ void Parser::ParseProtoDecl() { Expect(kTokenIntegerConstant); auto &field = AddField(struct_def, name, type); field.doc_comment = field_comment; - field.required = required; + if (!IsScalar(type.base_type)) field.required = required; // See if there's a default specified. if (IsNext('[')) { if (attribute_ != "default") Error("\'default\' expected"); diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h index c468b10..6564a9b 100644 --- a/tests/monster_test_generated.h +++ b/tests/monster_test_generated.h @@ -31,7 +31,7 @@ inline const char **EnumNamesColor() { return names; } -inline const char *EnumNameColor(Color e) { return EnumNamesColor()[e - Color_Red]; } +inline const char *EnumNameColor(Color e) { return EnumNamesColor()[static_cast(e) - static_cast(Color_Red)]; } enum Any { Any_NONE = 0, @@ -44,7 +44,7 @@ inline const char **EnumNamesAny() { return names; } -inline const char *EnumNameAny(Any e) { return EnumNamesAny()[e]; } +inline const char *EnumNameAny(Any e) { return EnumNamesAny()[static_cast(e)]; } inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, Any type); -- 2.7.4