Re: -Wshift-negative-value

Daniel Jour <[email protected]>
Newsgroups gmane.lisp.clisp.devel
Message-ID <CACZHyTP2bZqVrsq8M7CNwr=9tizM6JzyzX3Q2EmPiPvELxwgoQ@mail.gmail.com>
> > > As I said on 2017-02-08, diagnostics from -Wshift-negative-value are
> > > most probably just noise.
> >
> > Why not disable them then?
>
> Feel free to do so. Good idea.

Actually, this is is a very (very) bad idea. Applying a (left) shift to a
negative value (or shifting by a negative value) is undefined behavior
since (AFAIK) C99 (which is what we - at least in September - wanted to
target).

Quote from (C11) standard (draft) [1]:

"The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits
are filled with zeros. [..] If E1 has a signed type and nonnegative value
[..] otherwise, the behavior is undefined."
N1570 §6.5.7/4

Thus every single one of those warnings is a possible Heisenbug.
Any random optimizer pass of any compiler could horribly break our code. We
could force compilation without any optimization to reduce the risk of
hitting such a case, but that's not really reasonable.

[1]: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford

_______________________________________________
clisp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clisp-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.