Fix operator==() generated for field of fixed sized array (#7749)

* Fix operator==() generated for field of fixed sized array

* Compare address

* noexcept

* Grammer

Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
Saman
2023-01-06 12:11:11 +08:00
committed by GitHub
parent 07d9485146
commit 74b5195089
5 changed files with 69 additions and 9 deletions

View File

@@ -2044,7 +2044,6 @@ class CppGenerator : public BaseGenerator {
const auto accessor = Name(field) + accessSuffix;
const auto lhs_accessor = "lhs." + accessor;
const auto rhs_accessor = "rhs." + accessor;
if (!field.deprecated && // Deprecated fields won't be accessible.
field.value.type.base_type != BASE_TYPE_UTYPE &&
(field.value.type.base_type != BASE_TYPE_VECTOR ||
@@ -2067,6 +2066,8 @@ class CppGenerator : public BaseGenerator {
" const &b) { return (a == b) || (a && b && *a == *b); })";
compare_op += "(" + equal_length + " && " + elements_equal + ")";
} else if (field.value.type.base_type == BASE_TYPE_ARRAY) {
compare_op += "(*" + lhs_accessor + " == *" + rhs_accessor + ")";
} else {
compare_op += "(" + lhs_accessor + " == " + rhs_accessor + ")";
}