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

    <tr>
        <th>Summary</th>
        <td>
            [Clang] False positive when checking `-Warray-bounds` for C-arrays
        </td>
    </tr>

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

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

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

<pre>
    Repro:

Checking if it is fine to access array before doing it, does not prevent `-Warray-bounds` warning.

```c++
template <class T, unsigned N>
constexpr auto size(const T (&)[N]) {
    return N;
}

template<class R>
constexpr bool test(const R& r) {
    if(size(r) > 1) {
 (void) (r[1] + 1); // if we remove `+ 1`, the error will disappear
 }
    return true;
}

constexpr int data[] = {10};
static_assert(test(data));
```

Result:

```console
<source>:9:17: warning: array index 1 is past the end of the array (that has type 'const int[1]') [-Warray-bounds]
        (void) (r[1] + 1); // if we remove `+ 1`, the error will disappear
                ^ ~
<source>:15:15: note: in instantiation of function template specialization 'test<int[1]>' requested here
static_assert(test(data));
              ^
<source>:7:21: note: array 'r' declared here
constexpr bool test(const R& r) {
 ^
```

Compiler explorer: https://godbolt.org/z/d7b55PTb8
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VcGOozgQ_ZrKpZQIigDhwKGTdA4r7WjVammPKwNF8I5js7ZJunPYb18Zku5MJnvoyyCEraLMq3rvGQvn5F4zl5CuId3OxOA7Y8vffhfnwX6XfJL1eVaZ5r184d4aSJ4g2kJ0eW46rr9LvUfZovQoHbZSM3qDoq7ZORTWinesuDWWsTFjqgfaYGPYoTYee8tH1h4hi-Z_junzygy6cZBFeBJWS71f3GJCFk13DbQO9xj1fOiV8IyQbGolnMPXADPosb0Gv0HyPGXWRjvPb71FMXiDTp4ZaDVG8RWBVkAZUAHp-hukW6ACIb-AICJa9oPV4XuXIOTb2_K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