[cfe-dev] cfe-dev Digest, Vol 50, Issue 23

Matthieu Monrocq matthieu.monrocq at gmail.com
Mon Aug 8 09:11:33 PDT 2011


> Date: Mon, 8 Aug 2011 09:42:02 +0100
> From: Peter Geoghegan <peter at 2ndquadrant.com>
> Subject: Re: [cfe-dev] Possibly invalid enum tautology warning
> To: John McCall <rjmccall at apple.com>
> Cc: cfe-dev at cs.uiuc.edu
> Message-ID:
>        <CAEYLb_U66g2xNc1g_uoJRdErxsjpr-kO=6bEVmeS=ehs+Enfxw at mail.gmail.com
> >
> Content-Type: text/plain; charset=windows-1252
>
> On 8 August 2011 01:50, John McCall <rjmccall at apple.com> wrote:
> > I still consider this a useful warning, even on enum types. ?When I
> > was implementing it, I was persuaded that we ought to have a
> > special case for comparing against an enumerator which happens
> > to be zero, because that was indicative of a particular common
> > and harmless idiom (specifically, things like if (v < v_first || v >
> v_last)).
> > I'm loathe to extend that to a direct comparison against zero, where
> > it really does seem like the programmer is specifically testing for
> > an error case and might be surprised to realize that their test never
> > triggers. ?People who really do want to litter their code with defensive
> > checks like this should just disable the tautological comparison
> > check ? it's not likely that it would only ever come up with enums.
>
> Respectfully, I have to wonder if that's a practical attitude. They
> may not want to "litter" their code. They may just want to do this
> exactly once, as for example Postgres was before a patch was committed
> that sidestepped the issue. Should they still have to disable the
> tautological comparison check?
>
> > Well, you're assuming that comparisons like this are always in overly-
> > defensive code where the tautology is harmless.
>
> No, I'm not. I'm quite simply taking issue with the fact that the
> tautology exists only because of a factor that is implementation
> defined.  /The tautology is not essential to the code/.
>
> --
> Peter Geoghegan ? ? ? http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training and Services
>

 Hello Peter:

> /The tautology is not essential to the code/.

It is, actually (though reported for the wrong reasons).

The Standard mandates that all values that an enum may take should be
comprised between the "min-value" and "max-value". If Clang has used an
unsigned type, then it means that there never was any value inferior to 0 in
the enum definition, and therefore the comparison is tautological.

Do note that assigning a value outside [min-value, max-value] to the enum
leads to unspecified behavior, and thus makes the code non-portable.

-- Matthieu.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110808/e9501205/attachment.html>


More information about the cfe-dev mailing list