Currently we have implicit conversion from LayoutUnit to int which is lossy, but explicit conversion from int to LayoutUnit.
In many cases, the intent of the lossy conversion is obvious, for example:
int intValue = layoutUnitValue.
However, in the following statement, the result is likely unexpected by the author:
LayoutRect r(LayoutUnit(0.5), LayoutUnit(0.5), 0, 0);
As conversion from LayoutUnit to int is implicit, the above statement will match the LayoutRect(int, int, int, int) constructor which is likely not the intention of the author.
LayoutSize, LayoutPoint and any other classes having overloaded constructors and/or methods accepting all LayoutUnit parameters and all int parameters also have the problem.
I'd like to mark LayoutUnit::operator int() and LayoutUnit::operator unsigned() as deleted to avoid unexpected implicit conversion. The original code where the implicit conversion would need to use LayoutUnit::toInt() or LayoutUnit::toUnsigned() explicitly.
However, in the CL doing the above, because I'm not sure what the actual intent of the LayoutRect constructor with mixed typed parameters, and I don't want to introduce any behavior change in the CL, I'd like to use toInt() and add TODO(this bug) at the sites.
Comment 1 by e...@chromium.org
, Aug 18 2016