C++ Logo


Advanced search

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

From: Nevin Liber <nevin_at_[hidden]>
Date: Mon, 12 Mar 2018 16:32:21 -0400
On Mon, Mar 12, 2018 at 4:10 PM, Myria <myriachan_at_[hidden]> wrote:

> The severity of the current situation is that I generally avoid signed
> integers if I intend to do any arithmetic on them whatsoever, lest the
> compiler decide to make demons come out of my nose. And even then,
> I'm not safe:
> std::uint16_t x = 0xFFFF;
> x *= x; // undefined behavior on most modern platforms

Why is wrapping better, especially at the cost of sanitizers no longer
detecting this by default? Are you really getting a useful result here?

This is the problem with unsigned: we cannot tell the difference between
accidentally wrapping vs. intentionally wrapping.

> I would be happy if an option like -fwrapv were supported everywhere,
> but Visual Studio doesn't have such an option, and Microsoft has
> already denied requests for such an option to be implemented.

If this is *intentional*, I'd much rather have it reflected in the type
system (or some other mechanism) rather than changing all ints to wrap,
even by compiler flags.
 Nevin ":-)" Liber  <mailto:nevin_at_[hidden]>  +1-847-691-1404

Received on 2018-03-12 21:33:05