[compiler-rt] 433a63e - Fix ambiguous reversed operator error in sanitizer_mac.h (#135068)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 9 15:54:40 PDT 2025
Author: Ivan Tadeu Ferreira Antunes Filho
Date: 2025-04-09T18:54:37-04:00
New Revision: 433a63e117ebf22365ef1f3f595a49cbe9f0c88e
URL: https://github.com/llvm/llvm-project/commit/433a63e117ebf22365ef1f3f595a49cbe9f0c88e
DIFF: https://github.com/llvm/llvm-project/commit/433a63e117ebf22365ef1f3f595a49cbe9f0c88e.diff
LOG: 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
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_mac.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.h b/compiler-rt/lib/sanitizer_common/sanitizer_mac.h
index f0a97d098eea0..4de0605e18f03 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.h
@@ -37,9 +37,6 @@ struct VersionBase {
VersionBase(u16 major, u16 minor) : major(major), minor(minor) {}
- bool operator==(const VersionType &other) const {
- return major == other.major && minor == other.minor;
- }
bool operator>=(const VersionType &other) const {
return major > other.major ||
(major == other.major && minor >= other.minor);
@@ -47,6 +44,11 @@ struct VersionBase {
bool operator<(const VersionType &other) const { return !(*this >= other); }
};
+template <typename VersionType>
+bool operator==(const VersionType &self, const VersionType &other) {
+ return self.major == other.major && self.minor == other.minor;
+}
+
struct MacosVersion : VersionBase<MacosVersion> {
MacosVersion(u16 major, u16 minor) : VersionBase(major, minor) {}
};
More information about the llvm-commits
mailing list