[compiler-rt] Replace bool operator== for VersionType in sanitizer_mac.h (PR #135068)

Ivan Tadeu Ferreira Antunes Filho via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 9 15:47:27 PDT 2025


https://github.com/itf updated https://github.com/llvm/llvm-project/pull/135068

>From d471bf4a03643df0c67c50bd3c2a944db9c42e38 Mon Sep 17 00:00:00 2001
From: Ivan Tadeu Ferreira Antunes Filho <antunesi at google.com>
Date: Wed, 9 Apr 2025 14:53:33 -0400
Subject: [PATCH 1/2] Replace bool operator== for VersionType in
 sanitizer_mac.h

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
---
 compiler-rt/lib/sanitizer_common/sanitizer_mac.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.h b/compiler-rt/lib/sanitizer_common/sanitizer_mac.h
index f0a97d098eea0..ebf013e8e917b 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.h
@@ -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) {
+    return self.major == other.major && self.minor == other.minor;
   }
   bool operator>=(const VersionType &other) const {
     return major > other.major ||

>From 6202d55bff256267e0c5dab75849333907e120fb Mon Sep 17 00:00:00 2001
From: Ivan Tadeu Ferreira Antunes Filho <antunesi at google.com>
Date: Wed, 9 Apr 2025 18:47:19 -0400
Subject: [PATCH 2/2] Update sanitizer_mac.h

---
 compiler-rt/lib/sanitizer_common/sanitizer_mac.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.h b/compiler-rt/lib/sanitizer_common/sanitizer_mac.h
index ebf013e8e917b..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) {}
 
-  friend bool operator==(const VersionType &self, const VersionType &other) {
-    return self.major == other.major && self.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