<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - In C -Wtautological-constant-out-of-range-compare should not trigger for out of range enums"
href="http://llvm.org/bugs/show_bug.cgi?id=22062">22062</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>In C -Wtautological-constant-out-of-range-compare should not trigger for out of range enums
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>fredm@spamcop.net
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Given this code:
#include <stdio.h>
typedef enum o {
O_1 = 0,
O_2,
} o;
int main(int argc, char** argv) {
enum o e1 = -1;
if( e1 >= 2 ) {
printf( "That's not right\n" );
}
printf("e1:%d\n",e1);
return 0;
}
Clang warns as follows:
$ clang -Wall -std=c89 t1.c
t1.c:11:10: warning: comparison of constant 2 with expression of type 'enum
o'
is always false [-Wtautological-constant-out-of-range-compare]
if( e1 >= 2 ) {
~~ ^ ~
1 warning generated.
That is demonstrably untrue:
$ ./a.out
That's not right
e1:-1
I don't believe that it is correct to assert the range of an enum to be limited
to the declared values in C, while that is valid in C++.
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:
An identifier declared as an enumeration constant has type int.
6.7.2.2 says:
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.
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.
A similar issue appeared to be raised and fixed in <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED FIXED - Clang incorrectly throws -Wtautological-constant-out-of-range-compare with enums"
href="show_bug.cgi?id=16154">bug 16154</a>.
I have raised this in the cfe-users mailing list (14-Dec-2013) where it was
suggested to raise the issue as a PR. I am not quite sure how a year passed in
the interim :)</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>