From 0ac02b9084c0fa02ffa64397dd22a6155db13ba6 Mon Sep 17 00:00:00 2001 From: Lenny Maiorani Date: Sun, 18 Apr 2021 10:52:11 -0600 Subject: [PATCH] AK/Complex: C++20-compatible comparison operators Problem: - Clang correctly reports non-`const` member function comparison operators as ambiguous. Solution: - Make them `const`. --- AK/Complex.h | 4 ++-- AK/Tests/TestRefPtr.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/AK/Complex.h b/AK/Complex.h index 832ead8b96..6fe71d2efe 100644 --- a/AK/Complex.h +++ b/AK/Complex.h @@ -243,13 +243,13 @@ public: } template - constexpr bool operator==(const Complex& a) + constexpr bool operator==(const Complex& a) const { return (this->real() == a.real()) && (this->imag() == a.imag()); } template - constexpr bool operator!=(const Complex& a) + constexpr bool operator!=(const Complex& a) const { return !(*this == a); } diff --git a/AK/Tests/TestRefPtr.cpp b/AK/Tests/TestRefPtr.cpp index f823944b44..fed2022af6 100644 --- a/AK/Tests/TestRefPtr.cpp +++ b/AK/Tests/TestRefPtr.cpp @@ -119,7 +119,14 @@ TEST_CASE(assign_moved_self) { RefPtr 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); }