Skip to content

Reland "Replace bool operator== for VersionType in sanitizer_mac.h" #135276

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

Conversation

vitalybuka
Copy link
Collaborator

@vitalybuka vitalybuka commented Apr 10, 2025

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& (as "this") and const VersionType &). into a symmetric operator

Relands #135068

Created using spr 1.3.4
@vitalybuka vitalybuka changed the title Replace bool operator== for VersionType in sanitizer_mac.h Relate "Replace bool operator== for VersionType in sanitizer_mac.h" Apr 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 10, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Vitaly Buka (vitalybuka)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/135276.diff

1 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_mac.h (+6-3)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.h b/compiler-rt/lib/sanitizer_common/sanitizer_mac.h
index f0a97d098eea0..b0e4ac7f40745 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,12 @@ struct VersionBase {
   bool operator<(const VersionType &other) const { return !(*this >= other); }
 };
 
+template <typename VersionType>
+bool operator==(const VersionBase<VersionType> &self,
+                const VersionBase<VersionType> &other) {
+  return self.major == other.major && self.minor == other.minor;
+}
+
 struct MacosVersion : VersionBase<MacosVersion> {
   MacosVersion(u16 major, u16 minor) : VersionBase(major, minor) {}
 };

@vitalybuka vitalybuka requested a review from googlewalt April 10, 2025 22:55
@googlewalt
Copy link
Contributor

Thanks!

@vitalybuka vitalybuka changed the title Relate "Replace bool operator== for VersionType in sanitizer_mac.h" Reland "Replace bool operator== for VersionType in sanitizer_mac.h" Apr 11, 2025
@vitalybuka vitalybuka merged commit 862e719 into main Apr 11, 2025
13 checks passed
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/replace-bool-operator-for-versiontype-in-sanitizer_mach branch April 11, 2025 02:05
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
…lvm#135276)

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

Relands llvm#135068

Co-authored-by: Ivan Tadeu Ferreira Antunes Filho <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants