From: John Keeping <john@keeping.me.uk>
To: Antoine Pelisse <apelisse@gmail.com>
Cc: Max Horn <max@quendi.de>, git <git@vger.kernel.org>,
Johannes Sixt <j6t@kdbg.org>, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 2/2] fix clang -Wtautological-compare with unsigned enum
Date: Thu, 17 Jan 2013 11:00:08 +0000 [thread overview]
Message-ID: <20130117110008.GD4574@serenity.lan> (raw)
In-Reply-To: <CALWbr2wk+78zxGKCo-hCOwMuMOzdGspYvMu7PA6o0OYM3Y3m4A@mail.gmail.com>
On Thu, Jan 17, 2013 at 11:32:39AM +0100, Antoine Pelisse wrote:
> John, could you confirm that you trigger the -Wtautological-compare
> warning with your version of clang ?
Yes, the warning is still there with both 3.2 and a recent trunk build
but this patch squelches it.
> And that this patch makes clang compilation warning-free (with the
> very latest clang) ?
There is one remaining warning on pu which hasn't been discussed in this
thread as far as I can see. I'll send a patch shortly.
There's also a warning that triggers with clang 3.2 but not clang trunk, which
I think is a legitimate warning - perhaps someone who understands integer type
promotion better than me can explain why the code is OK (patch->score is
declared as 'int'):
builtin/apply.c:1044:47: warning: comparison of constant 18446744073709551615
with expression of type 'int' is always false
[-Wtautological-constant-out-of-range-compare]
if ((patch->score = strtoul(line, NULL, 10)) == ULONG_MAX)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~
> On Wed, Jan 16, 2013 at 11:47 PM, Antoine Pelisse <apelisse@gmail.com> wrote:
> > Create a GREP_HEADER_FIELD_MIN so we can check that the field value is
> > sane and silent the clang warning.
> >
> > Clang warning happens because the enum is unsigned (this is
> > implementation-defined, and there is no negative fields) and the check
> > is then tautological.
> >
> > Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
> > ---
> > I tried to consider discussion [1] and this [2] discussion on clang's list
> >
> > With these two patches and the patch from Max Horne, I'm finally able to
> > compile with CC=clang CFLAGS=-Werror.
> >
> > [1]: http://thread.gmane.org/gmane.comp.version-control.git/184908
> > [2]: http://clang-developers.42468.n3.nabble.com/Possibly-invalid-enum-tautology-warning-td3233140.html
> >
> > grep.c | 3 ++-
> > grep.h | 3 ++-
> > 2 files changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/grep.c b/grep.c
> > index 4bd1b8b..bb548ca 100644
> > --- a/grep.c
> > +++ b/grep.c
> > @@ -625,7 +625,8 @@ static struct grep_expr *prep_header_patterns(struct grep_opt *opt)
> > for (p = opt->header_list; p; p = p->next) {
> > if (p->token != GREP_PATTERN_HEAD)
> > die("bug: a non-header pattern in grep header list.");
> > - if (p->field < 0 || GREP_HEADER_FIELD_MAX <= p->field)
> > + if (p->field < GREP_HEADER_FIELD_MIN ||
> > + GREP_HEADER_FIELD_MAX <= p->field)
> > die("bug: unknown header field %d", p->field);
> > compile_regexp(p, opt);
> > }
> > diff --git a/grep.h b/grep.h
> > index 8fc854f..e4a1df5 100644
> > --- a/grep.h
> > +++ b/grep.h
> > @@ -28,7 +28,8 @@ enum grep_context {
> > };
> >
> > enum grep_header_field {
> > - GREP_HEADER_AUTHOR = 0,
> > + GREP_HEADER_FIELD_MIN = 0,
> > + GREP_HEADER_AUTHOR = GREP_HEADER_FIELD_MIN,
> > GREP_HEADER_COMMITTER,
> > GREP_HEADER_REFLOG,
> >
> > --
> > 1.8.1.1.435.g20d29be.dirty
> >
next prev parent reply other threads:[~2013-01-17 11:00 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-16 14:53 [PATCH] fix some clang warnings Max Horn
2013-01-16 16:04 ` Jeff King
2013-01-16 16:53 ` Junio C Hamano
2013-01-16 17:12 ` Antoine Pelisse
2013-01-16 17:18 ` John Keeping
2013-01-16 17:26 ` Max Horn
2013-01-16 17:50 ` Jeff King
2013-01-16 18:00 ` Jeff King
2013-01-16 18:09 ` Jeff King
2013-01-16 18:12 ` John Keeping
2013-01-16 18:15 ` Jeff King
2013-01-16 18:21 ` Antoine Pelisse
2013-01-16 18:22 ` John Keeping
2013-01-16 18:24 ` Jeff King
2013-01-16 19:01 ` John Keeping
2013-01-17 10:24 ` John Keeping
2013-01-16 22:47 ` [PATCH 1/2] fix clang -Wconstant-conversion with bit fields Antoine Pelisse
2013-01-16 22:47 ` [PATCH 2/2] fix clang -Wtautological-compare with unsigned enum Antoine Pelisse
2013-01-16 23:10 ` Antoine Pelisse
2013-01-17 10:32 ` Antoine Pelisse
2013-01-17 11:00 ` John Keeping [this message]
2013-01-17 11:23 ` [PATCH] combine-diff: suppress a clang warning John Keeping
2013-01-17 16:44 ` [PATCH 2/2] fix clang -Wtautological-compare with unsigned enum Linus Torvalds
2013-01-17 16:56 ` Antoine Pelisse
2013-01-17 17:02 ` John Keeping
2013-01-18 17:15 ` Phil Hord
2013-01-18 18:52 ` Linus Torvalds
2013-01-16 23:08 ` [PATCH 1/2] fix clang -Wconstant-conversion with bit fields John Keeping
2013-01-16 23:09 ` Antoine Pelisse
2013-01-16 23:15 ` Antoine Pelisse
2013-01-16 23:43 ` Junio C Hamano
2013-01-16 23:46 ` Junio C Hamano
2013-01-16 18:03 ` [PATCH] fix some clang warnings Tomas Carnecky
2013-01-16 18:12 ` Matthieu Moy
2013-02-01 5:37 ` Miles Bader
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130117110008.GD4574@serenity.lan \
--to=john@keeping.me.uk \
--cc=apelisse@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j6t@kdbg.org \
--cc=max@quendi.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.