1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:37:46 +00:00

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.
This commit is contained in:
Daniel Bertalan 2021-07-05 20:14:29 +02:00 committed by Gunnar Beutner
parent 494ead3eb8
commit 2ee39ed5f0

View file

@ -54,7 +54,6 @@ public:
, m_high(high) , m_high(high)
{ {
} }
constexpr T& low() constexpr T& low()
{ {
return m_low; return m_low;
@ -314,6 +313,11 @@ public:
return *this; return *this;
} }
static constexpr size_t my_size()
{
return sizeof(R);
}
// Arithmetics // Arithmetics
// implies size of less than u64, so passing references isn't useful // implies size of less than u64, so passing references isn't useful
@ -335,7 +339,7 @@ public:
}; };
} }
template<Unsigned U> template<Unsigned U>
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 lower = m_low.addc(other, carry);
T higher = m_high.addc(0u, carry); T higher = m_high.addc(0u, carry);
@ -377,7 +381,7 @@ public:
}; };
} }
template<Unsigned U> template<Unsigned U>
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); return other.addc(*this, carry);
} }
@ -474,7 +478,7 @@ public:
// FIXME: no restraints on this // FIXME: no restraints on this
template<Unsigned U> template<Unsigned U>
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? // FIXME: Is there a better way to raise a division by 0?
// Maybe as a compiletime warning? // Maybe as a compiletime warning?