-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Replace bool operator== for VersionType in sanitizer_mac.h #135068
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
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
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Ivan Tadeu Ferreira Antunes Filho (itf) ChangesFixes 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/135068.diff 1 Files Affected:
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 ||
|
@@ -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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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;
}
LGTM |
This broke GreenDragon: https://ci.swift.org/view/all/job/llvm.org/view/LLDB/job/as-lldb-cmake/23697/console
|
…135127) Reverts #135068 because it breaks building compiler-rt on Darwin. https://green.lab.llvm.org/job/clang-stage1-RA/ https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/ https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake/
…er_mac.h" (#135127) Reverts llvm/llvm-project#135068 because it breaks building compiler-rt on Darwin. https://green.lab.llvm.org/job/clang-stage1-RA/ https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/ https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake/
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
…lvm#135127) Reverts llvm#135068 because it breaks building compiler-rt on Darwin. https://green.lab.llvm.org/job/clang-stage1-RA/ https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/ https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake/
bool operator>=(const VersionType &other) const { | ||
return major > other.major || | ||
(major == other.major && minor >= other.minor); | ||
} | ||
bool operator<(const VersionType &other) const { return !(*this >= other); } | ||
}; | ||
|
||
template <typename VersionType> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this work?
struct VersionBase {
u16 major;
u16 minor;
VersionBase(u16 major, u16 minor) : major(major), minor(minor) {}
template <typename VersionType>
bool operator==(const VersionType &other) const {
return major == other.major && minor == other.minor;
}
template <typename VersionType>
bool operator>=(const VersionType &other) const {
return major > other.major ||
(major == other.major && minor >= other.minor);
}
template <typename VersionType>
bool operator<(const VersionType &other) const { return !(*this >= other); }
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this will defy the purpose of two different types.
then probably:
template <typename VersionType>
bool operator==(const VersionBase<VersionType> &self, const VersionBase<VersionType> &other) {
return self.major == other.major && self.minor == other.minor;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't. The code (e.g. MacosVersion immediately below) expects VersionBase to be a template. Defining an matching operator!=
seems to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it's the same issue, we declare operator which can be a candidate for any type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you replied to first one, which is wrong.
However this one should work. I'll try locally
template <typename VersionType>
bool operator==(const VersionBase<VersionType> &self, const VersionBase<VersionType> &other) {
return self.major == other.major && self.minor == other.minor;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you replied to first one, which is wrong.
However this one should work. I'll try locally
template <typename VersionType> bool operator==(const VersionBase<VersionType> &self, const VersionBase<VersionType> &other) { return self.major == other.major && self.minor == other.minor; }
Yeah that seems to work.
…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 #135068 Co-authored-by: Ivan Tadeu Ferreira Antunes Filho <[email protected]>
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
…lvm#135127) Reverts llvm#135068 because it breaks building compiler-rt on Darwin. https://green.lab.llvm.org/job/clang-stage1-RA/ https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/ https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake/
…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]>
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