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