<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 --- - uninitialized warning refers to practically irrelevant code"
href="http://llvm.org/bugs/show_bug.cgi?id=18046">18046</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>uninitialized warning refers to practically irrelevant code
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>FreeBSD
</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>M8R-9yw8a5@mailinator.com
</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>1. Source code (x.c):
int main(void)
{
for(const char *p = ""; p; ) { }
for(const char *q; (q = q + 1); ) { }
}
2. Command line:
clang -Wall x.c
3. Output:
x.c:3:26: warning: variable 'q' is used uninitialized whenever 'for' loop exits
because its condition is false [-Wsometimes-uninitialized]
for(const char *p = ""; p; ) { }
^
x.c:4:26: note: uninitialized use occurs here
for(const char *q; (q = q + 1); ) { }
^
x.c:3:26: note: remove the condition if it is always true
for(const char *p = ""; p; ) { }
^
x.c:4:19: note: initialize the variable 'q' to silence this warning
for(const char *q; (q = q + 1); ) { }
^
= 0
1 warning generated.
4. Notes:
a) Using ``++q'' instead of ``(q = q + 1)'' causes the reference to the
other loop to go away (the uninitialized warning for ``q'' is still given).
b) If ``q'' is instead created and used (without initialization) in a
non-loop block (eg., ``{ const char *q; (q = q + 1); }''), then the reference
also goes away.
c) Changing the condition of the 1st loop to ``1'' (always true) causes the
said warnings to go away.</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>