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:
cosmith-nvidia
2025-11-04 16:43:00 -08:00
committed by GitHub
parent 5fe90a9160
commit 4173b84d4b
5 changed files with 49 additions and 5 deletions

View File

@@ -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) {