Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler-rt/lib/sanitizer_common/sanitizer_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ struct VersionBase {

VersionBase(u16 major, u16 minor) : major(major), minor(minor) {}

bool operator==(const VersionType &other) const {
return major == other.major && minor == other.minor;
friend bool operator==(const VersionType &self, const VersionType &other) {
Copy link
Collaborator

@vitalybuka vitalybuka Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fields are public, it does not need need to be fried or even a method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to access VersionType without it being a method? If we didn't depend on the template for the comparison, it would be simple.

And without it being a friend, I'm unsure how to create a symmetric binary operator. Removing "friend" would cause it to have 3 parameters, and if we remove &self, we go back to the original issue we are trying to fix.

Copy link
Contributor

@googlewalt googlewalt Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want a standalone function, defined outside of the struct:

template <typename VersionType>
bool operator==(const VersionType &self, const VersionType &other) {
  return self.major == other.major && self.minor == other.minor;
}

return self.major == other.major && self.minor == other.minor;
}
bool operator>=(const VersionType &other) const {
return major > other.major ||
Expand Down