mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-03 12:21:23 +00:00
Fix --gen-compare to not generate comparators for native types. (#8681)
Per the definition of --gen-compare: only generate comparators for object API generated structs. Types annoated with native_type must define their own comparators if `--gen-compare` is enabled. Also enables --gen-compare for native_type_test and fixes the test by adding a comparator for the Native::Vector3D type.
This commit is contained in:
@@ -512,7 +512,8 @@ class CppGenerator : public BaseGenerator {
|
||||
// Generate forward declarations for all equal operators
|
||||
if (opts_.generate_object_based_api && opts_.gen_compare) {
|
||||
for (const auto& struct_def : parser_.structs_.vec) {
|
||||
if (!struct_def->generated) {
|
||||
const auto native_type = struct_def->attributes.Lookup("native_type");
|
||||
if (!struct_def->generated && !native_type) {
|
||||
SetNameSpace(struct_def->defined_namespace);
|
||||
auto nativeName = NativeName(Name(*struct_def), struct_def, opts_);
|
||||
code_ += "bool operator==(const " + nativeName + " &lhs, const " +
|
||||
@@ -2190,6 +2191,12 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
void GenCompareOperator(const StructDef& struct_def,
|
||||
const std::string& accessSuffix = "") {
|
||||
// Do not generate compare operators for native types.
|
||||
const auto native_type = struct_def.attributes.Lookup("native_type");
|
||||
if (native_type) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string compare_op;
|
||||
for (auto it = struct_def.fields.vec.begin();
|
||||
it != struct_def.fields.vec.end(); ++it) {
|
||||
|
||||
Reference in New Issue
Block a user