diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 75c86c091..36a624940 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -1638,7 +1638,9 @@ class CppGenerator : public BaseGenerator { auto full_struct_name = GetUnionElement(ev, true, true); // @TODO: Mby make this decisions more universal? How? - code_.SetValue("U_GET_TYPE", Name(field) + UnionTypeFieldSuffix()); + code_.SetValue( + "U_GET_TYPE", + EscapeKeyword(field.name + UnionTypeFieldSuffix())); code_.SetValue( "U_ELEMENT_TYPE", WrapInNameSpace(u->defined_namespace, GetEnumValUse(*u, ev))); @@ -1994,8 +1996,9 @@ class CppGenerator : public BaseGenerator { std::string GenUnionUnpackVal(const FieldDef &afield, const char *vec_elem_access, const char *vec_type_access) { - return afield.value.type.enum_def->name + "Union::UnPack(" + "_e" + - vec_elem_access + ", " + Name(afield) + UnionTypeFieldSuffix() + + return afield.value.type.enum_def->name + + "Union::UnPack(" + "_e" + vec_elem_access + ", " + + EscapeKeyword(afield.name + UnionTypeFieldSuffix()) + "()" + vec_type_access + ", _resolver)"; }