We shouldn't be assuming that enum values are in range in C, only in C++ (and even there it's controversial). Please file a PR.<br><br><div>On Sat Dec 14 2013 at 2:55:48 PM, Fred <<a href="mailto:fredm@spamcop.net" target="_blank">fredm@spamcop.net</a>> wrote:</div>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks for confirming that this also happens in other clang branches.<br>
<br>
In C an enumeration is defined as an enumeration constant and 6.4.4.3 of the draft C standard April 12, 2011 ISO/IEC 9899:201x I am looking at says:<br>
An identifier declared as an enumeration constant has type int.<br>
<br>
6.7.2.2 says:<br>
Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined,128) but shall be capable of representing the values of all the members of the enumeration.<br>

<br>
As long as it isn't forbidden to assign out-of-enumeration values to an enumeration I think that it is invalid to say that the comparison of any out of declared enumeration range value is guaranteed to be tautological - I have certainly seen lots of code that uses out of enumeration values to flag that a value is uninitialised etc. (no comment on how good the style is). Of course, code of that form would need to use values that are in the range of the implementation-defined type that is used to have a chance of being meaningful.<br>

<br>
Thanks,<br>
Fred<br>
<br>
On 15 Dec 2013, at 5:42, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br>
<br>
> I believe this does also happen in ToT Clang & there's been some discussion (perhaps it's on an internal Google bug, I forget) about the right thing to do here.<br>
><br>
> I think one of the issues is that your code isn't guaranteed to behave that way - it's possible for an implementation to map -1 onto one of the existing 0/1 bit values of the enum (the enum only needs to be one bit wide (obviously sizeof won't reflect that, it still has to take at least a byte of storage)). Arguably, though, it's still possibel on some implementations (including Clang) for it to have such a value...<br>

><br>
> The wording is tricky - between underlying types and ranges, etc, I don't have it all perfectly straight in my head.<br>
><br>
><br>
> On Sat, Dec 14, 2013 at 3:17 AM, Fred <<a href="mailto:fredm@spamcop.net" target="_blank">fredm@spamcop.net</a>> wrote:<br>
> Hi all,<br>
> I am seeing the -Wtautological-constant-out-<u></u>of<u></u>-range-compare warning for the first time.<br>
><br>
> With this Apple clang version:<br>
> $ clang --version<br>
> Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)<br>
> Target: x86_64-apple-darwin13.0.0<br>
> Thread model: posix<br>
><br>
> In this program:<br>
> #include <stdio.h><br>
><br>
> typedef enum o {<br>
>     O_1 = 0,<br>
>     O_2,<br>
> } o;<br>
><br>
> int main(int argc, char** argv) {<br>
>   enum o e1 = -1;<br>
><br>
>   if( e1 >= 2 ) {<br>
>     printf( "That's not right\n" );<br>
>   }<br>
><br>
>   printf("e1:%d\n",e1);<br>
><br>
>   return 0;<br>
> }<br>
><br>
> Compiled thus, I get the warning that my if test above will always evaluate as false:<br>
> $ clang -Wall -std=c89 t1.c<br>
> t1.c:11:10: warning: comparison of constant 2 with expression of type 'enum o'<br>
>       is always false [-Wtautological-constant-out-<u></u>o<u></u>f-range-compare]<br>
>   if( e1 >= 2 ) {<br>
>       ~~ ^  ~<br>
> 1 warning generated.<br>
><br>
> That is demonstrably untrue:<br>
> $ ./a.out<br>
> That's not right<br>
> e1:-1<br>
><br>
> Does this error also occur in the mainline clang? I am unsure whether to raise the issue with Apple or the clang developers.<br>
><br>
> Thanks,<br>
> Fred<br>
> ______________________________<u></u><u></u>_________________<br>
> cfe-users mailing list<br>
> <a href="mailto:cfe-users@cs.uiuc.edu" target="_blank">cfe-users@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailm<u></u>an/listinfo/cfe-users</a><br>
><br>
</blockquote>