Skip to content

Commit

Permalink
AK/Complex: C++20-compatible comparison operators
Browse files Browse the repository at this point in the history
Problem:
- Clang correctly reports non-`const` member function comparison
  operators as ambiguous.

Solution:
- Make them `const`.
  • Loading branch information
ldm5180 authored and awesomekling committed Apr 18, 2021
1 parent 97f4aa1 commit 0ac02b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions AK/Complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ class [[gnu::packed]] Complex {
}

template<AK::Concepts::Arithmetic U>
constexpr bool operator==(const Complex<U>& a)
constexpr bool operator==(const Complex<U>& a) const
{
return (this->real() == a.real()) && (this->imag() == a.imag());
}

template<AK::Concepts::Arithmetic U>
constexpr bool operator!=(const Complex<U>& a)
constexpr bool operator!=(const Complex<U>& a) const
{
return !(*this == a);
}
Expand Down
7 changes: 7 additions & 0 deletions AK/Tests/TestRefPtr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,14 @@ TEST_CASE(assign_moved_self)
{
RefPtr<Object> object = adopt(*new Object);
EXPECT_EQ(object->ref_count(), 1u);
#ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wself-move"
#endif
object = move(object);
#ifdef __clang__
# pragma clang diagnostic pop
#endif
EXPECT_EQ(object->ref_count(), 1u);
}

Expand Down

0 comments on commit 0ac02b9

Please sign in to comment.