[ub] A proposal to define signed overflow submitted?
Nevin Liber
nevin at eviloverlord.com
Mon Mar 12 21:32:21 CET 2018
On Mon, Mar 12, 2018 at 4:10 PM, Myria <myriachan at gmail.com> 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 eviloverlord.com> +1-847-691-1404
<(847)%20691-1404>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.open-std.org/pipermail/ub/attachments/20180312/991685da/attachment-0001.html
More information about the ub
mailing list