Skip to content

Commit 433a63e

Browse files
authored
Fix ambiguous reversed operator error in sanitizer_mac.h (#135068)
Fixes error: ISO C++20 considers use of overloaded operator '==' (with operand types 'MacosVersion' and 'MacosVersion') to be ambiguous despite there being a unique best viable function [-Werror,-Wambiguous-reversed-operator]. This converts the comparison operator from a non-symmetric operator (const VersionBase<VersionType>& (as "this") and const VersionType &). into a symmetric operator
1 parent 154507c commit 433a63e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_mac.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@ struct VersionBase {
3737

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

40-
bool operator==(const VersionType &other) const {
41-
return major == other.major && minor == other.minor;
42-
}
4340
bool operator>=(const VersionType &other) const {
4441
return major > other.major ||
4542
(major == other.major && minor >= other.minor);
4643
}
4744
bool operator<(const VersionType &other) const { return !(*this >= other); }
4845
};
4946

47+
template <typename VersionType>
48+
bool operator==(const VersionType &self, const VersionType &other) {
49+
return self.major == other.major && self.minor == other.minor;
50+
}
51+
5052
struct MacosVersion : VersionBase<MacosVersion> {
5153
MacosVersion(u16 major, u16 minor) : VersionBase(major, minor) {}
5254
};

0 commit comments

Comments
 (0)