C++ Logo


Advanced search

Re: [ub] A proposal to define signed overflow submitted?

From: Gabriel Dos Reis <gdr_at_[hidden]>
Date: Mon, 26 Feb 2018 14:12:59 +0000
While I am supportive of reducing the generality of binary representation currently allowed by the standards, I would be hard pressed to reduce it to only 2’s complement.
C++ should support at least the binary representations afforded by C, e.g. 2’s complement, 1’s complement, and sign-magnitude.
I wouldn’t support a “if nobody heard the tree fall, then it didn’t fall” approach.

From: ub-bounces_at_[hidden] <ub-bounces_at_[hidden]> On Behalf Of JF Bastien
Sent: Sunday, February 18, 2018 9:52 PM
To: WG21 UB study group SG12 <ub_at_[hidden]>
Subject: Re: [ub] A proposal to define signed overflow submitted?

On Sun, Feb 18, 2018 at 9:48 PM Lawrence Crowl <Lawrence_at_[hidden]<mailto:Lawrence_at_[hidden]>> wrote:
On 2/16/18, Freek Wiedijk <freek_at_[hidden]<mailto:freek_at_[hidden]>> wrote:
> Is there a good reason not to have it be implementation defined
> whether signed overflow is undefined or wrapping?

If integer overflow is undefined behavior, then it is wrong. Tools can
detect wrong programs and report them.

If integer overflow is wrapping, then one never knows whether or
not the programmer is relying on wrapper or would be surprised at
wrapping. No diagnostic is possible.

No disagreement. I wrote the paper the way I did because I want that discussion to conclude what the default should be, and what the more verbose alternate should be: UB or two’s complement?

There are many ways we can design this. I proposed the one I find more palatable, expecting others to disagree.

It would be great for a solid reasoning to emerge on the design.

Received on 2018-02-26 15:13:03