Bug 1791961 - mfbt: constify some operators to fix C++20 -Wambiguous-reversed-operator warnings. r=glandium
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. mfbt/tests/TestDoublyLinkedList.cpp:158:36 [-Wambiguous-reversed-operator] ISO C++20 considers use of overloaded operator '==' (with operand types 'SomeClass' and 'SomeClass') to be ambiguous despite there being a unique best viable function mfbt/tests/TestDoublyLinkedList.cpp:159:38 [-Wambiguous-reversed-operator] ISO C++20 considers use of overloaded operator '==' (with operand types 'SomeClass' and 'SomeClass') to be ambiguous despite there being a unique best viable function Depends on D179022 Differential Revision: https://phabricator.services.mozilla.com/D179023
This commit is contained in:
@@ -14,7 +14,9 @@ struct SomeClass : public DoublyLinkedListElement<SomeClass> {
|
||||
unsigned int mValue;
|
||||
explicit SomeClass(int aValue) : mValue(aValue) {}
|
||||
void incr() { ++mValue; }
|
||||
bool operator==(const SomeClass& other) { return mValue == other.mValue; }
|
||||
bool operator==(const SomeClass& other) const {
|
||||
return mValue == other.mValue;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ListType, size_t N>
|
||||
|
||||
Reference in New Issue
Block a user