<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 --- - No warning when comparing zero-valued enum with a pointer"
href="https://llvm.org/bugs/show_bug.cgi?id=28682">28682</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>No warning when comparing zero-valued enum with a pointer
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.8
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</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>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>martin.thomson@gmail.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>This C program produces a warning:
typedef enum { z = 0, nz = 1 } e;
int main() {
void *p = (void *)main; /* value doesn't matter */
return p == nz;
}
$ cc -Werror -Weverything -o main main.c
main.c:7:12: error: comparison between pointer and integer ('void *' and 'int')
[-Werror]
return p == nz;
~ ^ ~~
Change the line to `p == z` and it builds without complaint.
Comparing a pointer to an enum is completely braindead and it should - at the
very least - elicit a warning. (I did this myself and only found the error at
runtime.)
--
clang++ identifies this as a problem, but probably only because pointer types
in C++ are more distinctly defined:
$ clang++ -Weverything -o main main.c
... whining about my cast ...
main.c:7:12: error: comparison between pointer and integer ('void *' and 'int')
return p == z;
~ ^ ~</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>