<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59665>59665</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            -Wunsafe-buffer-usage warns for range-based for loop
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          davidstone
      </td>
    </tr>
</table>

<pre>
    The following statically safe code

```
void f() {
        int a[1] = {};
        for (auto x : a) {
        }
}
```

causes `clang -Wunsafe-buffer-usage` to emit

```
<source>:3:14: warning: unchecked operation on raw buffer in expression [-Wunsafe-buffer-usage]
        for (auto x : a) {
 ^
1 warning generated.
Compiler returned: 0
```

See it live: https://godbolt.org/z/WdzKTzT9P

Passing an array as the argument to the range-based for loop is guaranteed to be a safe construct (at least from the "accessing the elements of the array" perspective, which is what this warning is trying to address), so this warning should not trigger for that usage.

Additionally, the error message isn't especially helpful because it doesn't tell me what I should do instead, but from what I can tell this is a fallback message where we don't have a great automated suggestion. However, that's not especially relevant in this case because it shouldn't warn at all.

@haoNoQ @ziqingluo-90 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVF9v2zYQ_zT0y8GGRFly9KAHJ66xYcDQYQH6fCJPEleK9PjHrvPpB1JKmxRBZxjyyTze7w_viN6r0RB1rH5k9WmDMUzWdRKvSvpgDW16K-_d80QwWK3tTZkRfMCgBGp9B48DgbCSWHFixXF9NsX6za9XqyQMjD8w3gI7PL6mtsoEQFY_lqw-AatOefFwYtWPlME6YPwBY7DwDVh1BPy5StqxxN-D9_jLU2D05IE1hdBoRth-iSax3_ZxGMhto8eRWFNAsECzCr8QxKonb6MTxKpPrDpWrDqW-8Tths4oM6YwGjGR-EoS7IUcBmUNWAMOb7AAgjJA3y6OvE9rrH78mFG9ioL183-OAKs_LVH5ygdGMokDyd2y8mTni9LkwFGI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