[cfe-dev] Possibly invalid enum tautology warning

Peter Geoghegan peter at 2ndquadrant.com
Mon Aug 8 01:42:02 PDT 2011


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




More information about the cfe-dev mailing list