From 2ee39ed5f0dd2eab860547d64711103df88e1aca Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Mon, 5 Jul 2021 20:14:29 +0200 Subject: [PATCH] AK: Fix `UFixedBigInt` not building with Clang Clang does not like that we are trying to refer to our own size while our declaration is not yet complete, and fails to compile this file. This is fixed by introducing a function which returns the correct sizeof. This only gets evaluated in the `requires` clause after the whole class has been parsed, so it will compile fine. --- AK/UFixedBigInt.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/AK/UFixedBigInt.h b/AK/UFixedBigInt.h index d1dc13eba9..9cb0cace61 100644 --- a/AK/UFixedBigInt.h +++ b/AK/UFixedBigInt.h @@ -54,7 +54,6 @@ public: , m_high(high) { } - constexpr T& low() { return m_low; @@ -314,6 +313,11 @@ public: return *this; } + static constexpr size_t my_size() + { + return sizeof(R); + } + // Arithmetics // implies size of less than u64, so passing references isn't useful @@ -335,7 +339,7 @@ public: }; } template - requires(sizeof(R) > sizeof(U) && sizeof(T) > sizeof(u64)) constexpr R addc(const U& other, bool& carry) const + requires(my_size() > sizeof(U) && sizeof(T) > sizeof(u64)) constexpr R addc(const U& other, bool& carry) const { T lower = m_low.addc(other, carry); T higher = m_high.addc(0u, carry); @@ -377,7 +381,7 @@ public: }; } template - requires(sizeof(R) < sizeof(U)) constexpr U addc(const U& other, bool& carry) const + requires(my_size() < sizeof(U)) constexpr U addc(const U& other, bool& carry) const { return other.addc(*this, carry); } @@ -474,7 +478,7 @@ public: // FIXME: no restraints on this template - requires(sizeof(R) >= sizeof(U)) constexpr R div_mod(const U& divisor, U& remainder) const + requires(my_size() >= sizeof(U)) constexpr R div_mod(const U& divisor, U& remainder) const { // FIXME: Is there a better way to raise a division by 0? // Maybe as a compiletime warning?