Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] Incorrect operator==() generated for field of fixed sized array #7746

Closed
sunwen18 opened this issue Dec 28, 2022 · 0 comments
Closed

Comments

@sunwen18
Copy link
Contributor

Given a struct with a fixed sized array of scalar type

struct Somestruct {
    items: [float:3];
    tag: uint8;
}

flatc (with the --gen-compare flag) will generate c++ code that includes something like this:

FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Somestruct FLATBUFFERS_FINAL_CLASS {
private:
  float items_[3];
  uint8_t tag_;
  int8_t padding0__;  int16_t padding1__;
public:
  const flatbuffers::Array<float, 3> *items() const {
    return &flatbuffers::CastToArray(items_);
  }
  inline bool operator==(const Somestruct &lhs, const Somestruct &rhs) {
    return
        (lhs.items() == rhs.items()) &&
        (lhs.tag() == rhs.tag());
  }
}

Since items() returns the pointer of Array, this is only comparing the address but not the dereferenced value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants