On 6/24/2016 3:55 PM, Andrei Alexandrescu wrote:
Interestingly, things like add(5u, -1) should succeed without overflow (returning 4u) even though the negative value is conceptually converted to a large positive number and the operation overflows. (I've implemented this behavior in the DbI checkedint.)
I believe adding such behavior is beyond the charter of checkedint. I understand the charter is to check for all overflow, undefined and implementation defined behaviors, and not go beyond that.
Pedantically, -1 is an int. But (unsigned op signed) converts the latter to unsigned, becoming (unsigned op unsigned), and so an overflow occurs.
