Disallow certain implicit conversions between integer types.

Disallow implicit conversion from ``uintN`` and ``intM`` when ``M > N``, and by extension, explicit
conversion between the same types are also disallowed.
This commit is contained in:
hrkrshnn
2021-01-12 08:23:47 +01:00
parent 0e32fa8209
commit e107d51f46
6 changed files with 27 additions and 8 deletions
+5 -4
View File
@@ -508,12 +508,13 @@ BoolResult IntegerType::isImplicitlyConvertibleTo(Type const& _convertTo) const
if (_convertTo.category() == category())
{
IntegerType const& convertTo = dynamic_cast<IntegerType const&>(_convertTo);
if (convertTo.m_bits < m_bits)
// disallowing unsigned to signed conversion of different bits
if (isSigned() != convertTo.isSigned())
return false;
else if (convertTo.m_bits < m_bits)
return false;
else if (isSigned())
return convertTo.isSigned();
else
return !convertTo.isSigned() || convertTo.m_bits > m_bits;
return true;
}
else if (_convertTo.category() == Category::FixedPoint)
{