Bug 1791961 - xpcom: Fix C++20 -Wambiguous-reversed-operator warnings. r=emilio

clang is warning that C++20 expects comparison operators to be commutative: `a == b` and `b == a` should resolve to the same comparison operator function. Warnings about the comparison of const and non-const objects can be fixed by making the comparison operator function const.

xpcom/base/AvailableMemoryWatcherMac.cpp:404:14 [-Wambiguous-reversed-operator] ISO C++20 considers use of overloaded operator '==' (with operand types 'mozilla::MacMemoryPressureLevel' and 'mozilla::MacMemoryPressureLevel') to be ambiguous despite there being a unique best viable function
xpcom/base/AvailableMemoryWatcherMac.cpp:568:24 [-Wambiguous-reversed-operator] ISO C++20 considers use of overloaded operator '==' (with operand types 'mozilla::MacMemoryPressureLevel' and 'mozilla::MacMemoryPressureLevel') to be ambiguous despite there being a unique best viable function

Depends on D179024

Differential Revision: https://phabricator.services.mozilla.com/D179025
This commit is contained in:
Chris Peterson 2023-05-26 04:51:44 +00:00
parent 0d90734c1c
commit c5f254d17c
2 changed files with 5 additions and 3 deletions

View File

@ -26,8 +26,8 @@ class MacMemoryPressureLevel {
MacMemoryPressureLevel() : mValue(Value::eUnset) {}
MOZ_IMPLICIT MacMemoryPressureLevel(Value aValue) : mValue(aValue) {}
bool operator==(const Value& aRhsValue) { return mValue == aRhsValue; }
bool operator==(const MacMemoryPressureLevel& aRhs) {
bool operator==(const Value& aRhsValue) const { return mValue == aRhsValue; }
bool operator==(const MacMemoryPressureLevel& aRhs) const {
return mValue == aRhs.mValue;
}

View File

@ -222,7 +222,9 @@ class PLDHashTable {
Slot& operator=(Slot&& aOther) = default;
bool operator==(const Slot& aOther) { return mEntry == aOther.mEntry; }
bool operator==(const Slot& aOther) const {
return mEntry == aOther.mEntry;
}
PLDHashNumber KeyHash() const { return *HashPtr(); }
void SetKeyHash(PLDHashNumber aHash) { *HashPtr() = aHash; }