Boost logo

Boost :

Subject: Re: [boost] Is there interest in portable integer overflow detection, with policy based handling?
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2012-02-23 08:59:59


Le 23/02/12 06:11, Ben Robinson a écrit :
> On Wed, Feb 22, 2012 at 11:37 AM, Robert Ramey<ramey_at_[hidden]> wrote:
>
>> ... How is this resolved? To take a pathological case:
>>
>> unsigned int x = std::numeric_limits<unsigned int>::max();
>> x = x / (-1);
>>
>> Will this throw? or fail at compile time, or what?
>>
>> Robert Ramey
>>
>> You are absolutely correct. I am not sure how I missed that corner case
> considering that I have the negation operator, and multiplication by -1
> are accounted for. I will write additional unit tests and post a fix
> shortly.
I would expect the result type of dividing unsigned verified_int and
signed verified_int to be signed verified_int. Couldn't this help to
avoid the overflow on operator/()?
Of course, if the user assigns a signed to an unsigned, overflow must be
checked.
I would also prefer that there is no implicit conversion from signed to
unsigned verified_int. A specific cast could be used for this purpose.

unary minus operator on unsigned verified_int could also result on a
signed verified_int.

Just my 2 cts,
Vicente


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk