This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C PATCH for -Wshift-negative-value (PR c/66066)
- From: Marek Polacek <polacek at redhat dot com>
- To: Manuel López-Ibáñez <lopezibanez at gmail dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 11 May 2015 17:54:41 +0200
- Subject: Re: C PATCH for -Wshift-negative-value (PR c/66066)
- Authentication-results: sourceware.org; auth=none
- References: <20150511142112 dot GO3384 at redhat dot com> <5550C626 dot 9020009 at gmail dot com>
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").
My change means that we wouldn't complain unless -pedantic (to not upset
too many users). I'm not particularly fond of it, but it seems like the
simplest solution.
Marek