C++ operator== fails for native inline types
In Version v2.0.5 the generated C++ code for tables with native_inline elements fails to compile because it produces something like this (From the monster test): ((lhs.pos == rhs.pos) || (lhs.pos && rhs.pos && *lhs.pos == *rhs.pos))
In my case it produces the same but for a native_inline which are generated as structs. The problem does not happen in v2.0.0 so I searched the commits and it seems to be introduced in 962751a6ec4a0cf9552b1291231edfc60210e77b #6486.
Can you make a minimal example schema (and flatc generation options) to show the issue?
I ran into the same problem recently and made a minimal example in a gist.
The code is generated via
flatc -c --gen-object-api --gen-compare native.fbs
and fails to compile as mentioned as it tries to dereference the nat_type struct despite it not being a pointer.
Removing the gen-compare works but that defeats the purpose of course!
Thanks for the example, I'll take a look this weekend. Sorry for the delay.
Thanks for reporting!
I think something like the following would fix it (against an internal version so line numbers are off)
--- a/flatbuffers/src/idl_gen_cpp.cpp
+++ b/flatbuffers/src/idl_gen_cpp.cpp
@@ -1649,7 +1649,7 @@ class CppGenerator : public BaseGenerato
field.value.type.element != BASE_TYPE_UTYPE)) {
if (!compare_op.empty()) { compare_op += " &&\n "; }
auto accessor = Name(field) + accessSuffix;
- if (struct_def.fixed ||
+ if (struct_def.fixed || field.native_inline ||
field.value.type.base_type != BASE_TYPE_STRUCT) {
compare_op += "(lhs." + accessor + " == rhs." + accessor + ")";
} else {
Note that you would need to provide a comparison operator for your native type.
@mikaraento Thanks for the suggestion!
@GMellar and @kaffeewolf Let me know how this is now. I only fixed the native_inline stuff in the example. I am not sure the native_type had any issues, but let me know.