<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/122300>122300</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] Array access during constant evaluation is inconsistently rejected
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
cookiestarfish
</td>
</tr>
</table>
<pre>
I hope it is obvious from the example, clang should either reject both element accesses or accept both.
```
struct Base
{};
struct Derived : Base
{
int value;
};
static_assert([]() {
Derived d[4] {};
d[0] = Derived{.value=10};
d[1] = Derived{.value=20};
d[2] = Derived{.value=30};
d[3] = Derived{.value=40};
Base* b = d;
// does not compile
// return static_cast<Derived*>(b)[2].value;
// using a temporary compiles.
Derived* temp = static_cast<Derived*>(b);
return temp[2].value;
}() == 30);
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMU-2OozgQfBrzpzXI2BCSH_wgw0W6pzgZ6ATfGRy5m-jy9isTTzazsxqthISlquqPsssQ2cuC2IjqKKouMytPPjSD9_9ZJDbhbGnKej_em79h8lcEy2AJfH-zfiU4Bz8DTwj4v5mvDoV6h8GZ5QI0-dWNgJYnDBDwXxwYes8ToMMZFwYzDEiEBD5s5-sDz4VsxU6mT7bEYR0YjoYwIvVR1J3Qx3h-gh0Ge8MRhG5fibIFuzDcjFsxST5pDdvhH0OEgYXaPyyIB3WAJAd41h5FdSxF1cHrCJEQAbkBuvtgi_qYp7ZdIb_Qi2_o6itdfUPXX-n6G3opXy2Iis0v1UK_ScZUKoFCnYQ6weiRYPEMg5-v1uFnNCCvYYHk52CIhX7_6K1aof8Sat8LdUir5C8X8kujlexyAQOM89UHE-4fHSn_fB1x4kjahv6Dzk-D0rBR-5txojnpAegultbyqX4-ymxs9HjQB5NhU9R6V-qd3pfZ1BgjzztT9P1hxD3W9flQ6v2wk33Ra1VWY2YbJVUlC3koKrVTZT5iPRSqrNH0xW6szqKUOBvrcuduc-7DJbNEKzaFUlrKzJkeHW1hVWrLmVBxhSw0UfDWrxcSpXSWmH6WYMtuS_hDUXXQhmDuKYAwriGaPviF2CwMGP0wbP0Sk26XCFhiXNjdU5BxzNbgmon5SkK3j8u7WJ7WPh_8LNQpNk-_t2vwUSTUaVuGhDqlfW6N-hEAAP__hlRUGQ">