<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - Use of uninitialized variable is not reported when followed by initialization in loop"
   href="https://bugs.llvm.org/show_bug.cgi?id=49029">49029</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Use of uninitialized variable is not reported when followed by initialization in loop
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </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>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>aa1ronham@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following code does not produce any warnings when compiled with 'clang++
weird.cpp -Wall'

```
int main() {
    int x;
    for (int i = 0; i < 10; i++) {
        x += 1;
        x = 0;
    }
}
```
However, 'x' is uninitialized during the initial iteration through the loop. If
the 'x = 0;' line is removed:

```
int main() {
    int x;
    for (int i = 0; i < 10; i++) {
        x += 1;
    }
}
```

then a warning is produced when compiled with 'clang++ weird.cpp -Wall'

```
weird.cpp:4:9: warning: variable 'x' is uninitialized when used here
[-Wuninitialized]
        x += 1;
        ^
weird.cpp:2:10: note: initialize the variable 'x' to silence this warning
    int x;
         ^
          = 0
1 warning generated.
```

The statement 'x = 0;' occurs after the uninitialized use of x, so it should
not cause the warning to be suppressed.</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>