Commit 02261c4b authored by Peter Kasting's avatar Peter Kasting Committed by V8 LUCI CQ

Types on both sides of comparison operators should be the same.

This prevents "ambiguous call" warnings when compiling in C++20 mode.

Bug: chromium:1284275
Change-Id: I52f782aaddfad1920e4b2df5e916b2c292cc7cff
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3630346
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80458}
parent 8656d937
...@@ -322,22 +322,22 @@ class TimeBase : public TimeConstants { ...@@ -322,22 +322,22 @@ class TimeBase : public TimeConstants {
} }
// Comparison operators // Comparison operators
bool operator==(TimeClass other) const { bool operator==(const TimeBase<TimeClass>& other) const {
return us_ == other.us_; return us_ == other.us_;
} }
bool operator!=(TimeClass other) const { bool operator!=(const TimeBase<TimeClass>& other) const {
return us_ != other.us_; return us_ != other.us_;
} }
bool operator<(TimeClass other) const { bool operator<(const TimeBase<TimeClass>& other) const {
return us_ < other.us_; return us_ < other.us_;
} }
bool operator<=(TimeClass other) const { bool operator<=(const TimeBase<TimeClass>& other) const {
return us_ <= other.us_; return us_ <= other.us_;
} }
bool operator>(TimeClass other) const { bool operator>(const TimeBase<TimeClass>& other) const {
return us_ > other.us_; return us_ > other.us_;
} }
bool operator>=(TimeClass other) const { bool operator>=(const TimeBase<TimeClass>& other) const {
return us_ >= other.us_; return us_ >= other.us_;
} }
......
...@@ -150,11 +150,23 @@ class Vector { ...@@ -150,11 +150,23 @@ class Vector {
input.size() * sizeof(S) / sizeof(T)); input.size() * sizeof(S) / sizeof(T));
} }
bool operator==(const Vector<const T> other) const { bool operator==(const Vector<T>& other) const {
return std::equal(begin(), end(), other.begin(), other.end()); return std::equal(begin(), end(), other.begin(), other.end());
} }
bool operator!=(const Vector<const T> other) const { bool operator!=(const Vector<T>& other) const {
return !operator==(other);
}
template<typename TT = T>
std::enable_if_t<!std::is_const_v<TT>, bool> operator==(
const Vector<const T>& other) const {
return std::equal(begin(), end(), other.begin(), other.end());
}
template<typename TT = T>
std::enable_if_t<!std::is_const_v<TT>, bool> operator!=(
const Vector<const T>& other) const {
return !operator==(other); return !operator==(other);
} }
......
...@@ -45,10 +45,12 @@ class RegisterBase { ...@@ -45,10 +45,12 @@ class RegisterBase {
return reg_code_; return reg_code_;
} }
inline constexpr bool operator==(SubType other) const { inline constexpr bool operator==(
const RegisterBase<SubType, kAfterLastRegister>& other) const {
return reg_code_ == other.reg_code_; return reg_code_ == other.reg_code_;
} }
inline constexpr bool operator!=(SubType other) const { inline constexpr bool operator!=(
const RegisterBase<SubType, kAfterLastRegister>& other) const {
return reg_code_ != other.reg_code_; return reg_code_ != other.reg_code_;
} }
......
...@@ -140,8 +140,12 @@ class V8_EXPORT_PRIVATE INSTRUCTION_OPERAND_ALIGN InstructionOperand { ...@@ -140,8 +140,12 @@ class V8_EXPORT_PRIVATE INSTRUCTION_OPERAND_ALIGN InstructionOperand {
// APIs to aid debugging. For general-stream APIs, use operator<<. // APIs to aid debugging. For general-stream APIs, use operator<<.
void Print() const; void Print() const;
bool operator==(InstructionOperand& other) const { return Equals(other); } bool operator==(const InstructionOperand& other) const {
bool operator!=(InstructionOperand& other) const { return !Equals(other); } return Equals(other);
}
bool operator!=(const InstructionOperand& other) const {
return !Equals(other);
}
protected: protected:
explicit InstructionOperand(Kind kind) : value_(KindField::encode(kind)) {} explicit InstructionOperand(Kind kind) : value_(KindField::encode(kind)) {}
......
...@@ -206,10 +206,10 @@ class V8_EXPORT_PRIVATE LoadElimination final ...@@ -206,10 +206,10 @@ class V8_EXPORT_PRIVATE LoadElimination final
} }
static IndexRange Invalid() { return IndexRange(); } static IndexRange Invalid() { return IndexRange(); }
bool operator==(const IndexRange& other) { bool operator==(const IndexRange& other) const {
return begin_ == other.begin_ && end_ == other.end_; return begin_ == other.begin_ && end_ == other.end_;
} }
bool operator!=(const IndexRange& other) { return !(*this == other); } bool operator!=(const IndexRange& other) const { return !(*this == other); }
struct Iterator { struct Iterator {
int i; int i;
......
...@@ -355,10 +355,10 @@ class PageIteratorImpl ...@@ -355,10 +355,10 @@ class PageIteratorImpl
explicit PageIteratorImpl(PAGE_TYPE* p) : p_(p) {} explicit PageIteratorImpl(PAGE_TYPE* p) : p_(p) {}
PageIteratorImpl(const PageIteratorImpl<PAGE_TYPE>& other) : p_(other.p_) {} PageIteratorImpl(const PageIteratorImpl<PAGE_TYPE>& other) : p_(other.p_) {}
PAGE_TYPE* operator*() { return p_; } PAGE_TYPE* operator*() { return p_; }
bool operator==(const PageIteratorImpl<PAGE_TYPE>& rhs) { bool operator==(const PageIteratorImpl<PAGE_TYPE>& rhs) const {
return rhs.p_ == p_; return rhs.p_ == p_;
} }
bool operator!=(const PageIteratorImpl<PAGE_TYPE>& rhs) { bool operator!=(const PageIteratorImpl<PAGE_TYPE>& rhs) const {
return rhs.p_ != p_; return rhs.p_ != p_;
} }
inline PageIteratorImpl<PAGE_TYPE>& operator++(); inline PageIteratorImpl<PAGE_TYPE>& operator++();
......
...@@ -306,11 +306,11 @@ class PropertyDetails { ...@@ -306,11 +306,11 @@ class PropertyDetails {
return PropertyDetails(PropertyKind::kData, NONE, cell_type); return PropertyDetails(PropertyKind::kData, NONE, cell_type);
} }
bool operator==(PropertyDetails const& other) { bool operator==(PropertyDetails const& other) const {
return value_ == other.value_; return value_ == other.value_;
} }
bool operator!=(PropertyDetails const& other) { bool operator!=(PropertyDetails const& other) const {
return value_ != other.value_; return value_ != other.value_;
} }
...@@ -393,8 +393,6 @@ class PropertyDetails { ...@@ -393,8 +393,6 @@ class PropertyDetails {
return PropertyCellTypeField::decode(value_); return PropertyCellTypeField::decode(value_);
} }
bool operator==(const PropertyDetails& b) const { return value_ == b.value_; }
// Bit fields in value_ (type, shift, size). Must be public so the // Bit fields in value_ (type, shift, size). Must be public so the
// constants can be embedded in generated code. // constants can be embedded in generated code.
using KindField = base::BitField<PropertyKind, 0, 1>; using KindField = base::BitField<PropertyKind, 0, 1>;
......
...@@ -173,8 +173,12 @@ class IdentityMap : public IdentityMapBase { ...@@ -173,8 +173,12 @@ class IdentityMap : public IdentityMapBase {
V* operator*() { return entry(); } V* operator*() { return entry(); }
V* operator->() { return entry(); } V* operator->() { return entry(); }
bool operator!=(const Iterator& other) { return index_ != other.index_; } bool operator!=(const Iterator& other) const {
bool operator==(const Iterator& other) { return index_ == other.index_; } return index_ != other.index_;
}
bool operator==(const Iterator& other) const {
return index_ == other.index_;
}
private: private:
Iterator(IdentityMap* map, int index) : map_(map), index_(index) {} Iterator(IdentityMap* map, int index) : map_(map), index_(index) {}
......
...@@ -103,10 +103,10 @@ class V8_EXPORT_PRIVATE BytecodeIterator : public NON_EXPORTED_BASE(Decoder) { ...@@ -103,10 +103,10 @@ class V8_EXPORT_PRIVATE BytecodeIterator : public NON_EXPORTED_BASE(Decoder) {
ptr_ += OpcodeLength(ptr_, end_); ptr_ += OpcodeLength(ptr_, end_);
return *this; return *this;
} }
bool operator==(const iterator_base& that) { bool operator==(const iterator_base& that) const {
return this->ptr_ == that.ptr_; return this->ptr_ == that.ptr_;
} }
bool operator!=(const iterator_base& that) { bool operator!=(const iterator_base& that) const {
return this->ptr_ != that.ptr_; return this->ptr_ != that.ptr_;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment