<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/65119>65119</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang incorrectly permits undefined behavior with one past the end element for arrays
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
cmazakas
</td>
</tr>
</table>
<pre>
clang incorrectly treats this as a core constant expression:
https://godbolt.org/z/rfEzePTvn
```cpp
#include <vector>
constexpr auto tester() {
std::vector<int> v = {1, 2, 3, 4};
auto p = &v[std::size(v)];
int xs[] = {1, 2, 3, 4};
auto q = &xs[std::size(xs)];
return (&v[0] == p) && (&xs[0] == q);
}
static_assert(!tester());
```
This is clearly UB as it violates both the sequence container requirements and also relies on dereferencing a non-existent element.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMU0-PqzYQ_zTmMtrI2OQPBw6bzebcw-u5MmYS3Do28Qy8JJ--wkn2patWqoQGAb9_HmYMkTsGxEYst2K5K8zIfUyNPZmb-ctQ0cbu2lhvwhFcsDEltOyvwAkNE3DvCAyBARsTgo2B2AQGvAwJiVwMQr8LuRPyvWceaH5Se6H2x9i10fMipqNQ-5tQ-3T4vOFvP6Zwhz_qSt4vOwyPN0q7YP3YIQj9MaHlmIT-fCXlFHMCMCNHYCTGJNRGqBrEensHARB3cxz9_hT5cIGF_oQJhN7NyFKoD1Bz0XOpxHon9Bc_iw93rFpNYrn9UiR3Q6E2k1C1WP7iPJkuMFzo3vD_5ZWtzk-rTP3udaH_MEvIYwqQz59TyofrrDbknqiVUKsHIou_Qs6z7pfoeveqTmzY2T8MESbO_PK12_9gPv_kK__HPD6OwHo0yV_h9-08TI5hctEbRoI2cg_cIxCeRww2zxgbFzBBwvPoEp4wMIEJHRhPERJ6hwQxQIcJD5gwWBeOYCDE8IYXR4zzhPpMXBRdo7ta16bAplzVulKVlKroG5RY243dtJWx7UZqa1bLstParDs0eKgK1yiptNxoWdZaK7Uol1IfpMKulGiqtRWVxJNxfuH9dJonvXBEIzarZVnWhTctesprp1TAn5A_CqXmLUzNzHlrxyOJSnpHTL9U2LHHf9nJAdPJMcEYOjy4gB202JvJxQQ_HfcQA8JgiHM_MXTPHsAhJjApmSsVY_LNt0113I_twsaTUPs5w-P2NqT4J1oWap-Tk1D7fLK_AwAA__-AA0zb">