<html>
<head>
<base href="https://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 --- - -Wenum-compare doesn't catch mismatched enum value comparison in C mode"
href="https://llvm.org/bugs/show_bug.cgi?id=28847">28847</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>-Wenum-compare doesn't catch mismatched enum value comparison in C mode
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>ibadawi@cisco.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Consider this program (test.c)
enum foo_t {
foo1, foo2, foo3
};
enum bar_t {
bar1, bar2, bar3
};
int main(void) {
enum foo_t foo = foo1;
enum bar_t bar = bar1;
int cmp1 = foo < bar; // variable - variable
int cmp2 = foo < bar2; // variable - constant
int cmp3 = foo1 < bar3; // constant - constant
return cmp1 || cmp2 || cmp3;
}
If I compile this as C code, I only get a warning for the first comparison. If
I compile in C++ mode, I get a warning for all three.
$ clang -Wall test.c
test.c:13:20: warning: comparison of two values with different enumeration
types
('enum foo_t' and 'enum bar_t') [-Wenum-compare]
int cmp1 = foo < bar;
~~~ ^ ~~~
1 warning generated.
$ clang -Wall -x c++ test.c
test.c:13:20: warning: comparison of two values with different enumeration
types
('enum foo_t' and 'enum bar_t') [-Wenum-compare]
int cmp1 = foo < bar;
~~~ ^ ~~~
test.c:14:20: warning: comparison of two values with different enumeration
types
('enum foo_t' and 'bar_t') [-Wenum-compare]
int cmp2 = foo < bar2;
~~~ ^ ~~~~
test.c:15:21: warning: comparison of two values with different enumeration
types ('foo_t' and 'bar_t')
[-Wenum-compare]
int cmp3 = foo1 < bar3;
~~~~ ^ ~~~~
3 warnings generated.
I think the warnings should be emitted in C mode too. Tested with gcc 4.9.2 and
3 warnings are emitted for C code:
$ gcc -Wall test.c
test.c: In function 'main':
test.c:13:20: warning: comparison between 'enum foo_t' and 'enum bar_t'
[-Wenum-compare]
int cmp1 = foo < bar;
^
test.c:14:20: warning: comparison between 'enum foo_t' and 'enum bar_t'
[-Wenum-compare]
int cmp2 = foo < bar2;
^
test.c:15:21: warning: comparison between 'enum foo_t' and 'enum bar_t'
[-Wenum-compare]
int cmp3 = foo1 < bar3;
^</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>