On 2015.05.11 at 17:54 +0200, Marek Polacek wrote: > On Mon, May 11, 2015 at 05:09:26PM +0200, Manuel López-Ibáñez wrote: > > On 11/05/15 16:21, Marek Polacek wrote: > > >The -Wshift-negative-value patch caused grief since it breaks building > > >some programs. The following patch should alleviate the pain a bit: mark > > >a left shift of a negative value as non-const only if pedantic. > > > > Either this is not correct according to the guidelines ("the flag pedantic > > should not cause generated code differences or errors", > > https://gcc.gnu.org/wiki/DiagnosticsGuidelines) or the guidelines need > > updating. > [...] > > The problem here isn't in the -Wshift-negative-value warning itself; the > problem is with marking -1 << 0 as a non-constant: later on, we warn in > a context where a constant expression is needed ("initializer element is > not a constant expression"), and for e.g. int foo = -1 << 0 | 9; there's > an error ("initializer element is not constant").
I find both the warning and the error confusing. Instead of "is not a constant", it should rather say "invokes undefined behavior". Because it is not obvious at first sight why (-1 << 0 | 9) shouldn't be a constant expression. -- Markus