This is the mail archive of the
mailing list for the GCC project.
Re: C PATCH for -Wshift-negative-value (PR c/66066)
- From: Manuel LÃpez-IbÃÃez <lopezibanez at gmail dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 11 May 2015 20:14:49 +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> <20150511155440 dot GQ3384 at redhat dot com>
On 11 May 2015 at 17:54, Marek Polacek <firstname.lastname@example.org> wrote:
> 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").
Yes, I understand. What I'm saying is that if folding was done at the
moment that the constant is requested, this would be a case of
pedwarn-if-pedantic, which is exactly what Joseph is discussing here
for case (b):
It doesn't matter that the error "initializer element is not a
constant expression" is not given as long as an error (e.g., "left
shift of negative value is undefined according to ISO C99") is given
I'm sorry to sound so "pedantic" but we have faced this same issue in
the past (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19976#c7) and
the solution was to delay folding
> 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.
-Wpedantic (which is the same as -pedantic) should not give errors.
Otherwise, it would mean that someone who uses -Wpedantic-
-Wno-pedantic will silence the error, but someone that uses
-Werror=pedantic -Wno-error=pedantic will still see an error (!).
There is also no way to tell that error is related to -Wpedantic.
But if this is the accepted solution, please at least test
global_dc->pedantic_errors instead and put a big /* ???? This is a
hack to reject non-conforming programs with -pedantic-errors and
accept them otherwise. See
https://gcc.gnu.org/ml/gcc/2013-11/msg00253.html about to fix this