<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54910>54910</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
False positive clang-analyzer-core.UndefinedBinaryOperatorResult with init list
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
chrchr-github
</td>
</tr>
</table>
<pre>
This should be legal, since
_Every initializer clause is [sequenced before](https://en.cppreference.com/w/cpp/language/eval_order) any initializer clause that follows it in the braced-init-list._ (https://en.cppreference.com/w/cpp/language/list_initialization)
~~~
#include <iostream>
int main() {
int b[3] = { 1, b[0] + 1, b[1] + 1 };
std::cout << b[0] << ' ' << b[1] << ' ' << b[2];
}
~~~
clang-tidy reports:
~~~
[<source>:3:26: warning: The left operand of '+' is a garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult]
int b[3] = { 1, b[0] + 1, b[1] + 1 };
~~~~ ^
[<source>:3:26: note: The left operand of '+' is a garbage value]
int b[3] = { 1, b[0] + 1, b[1] + 1 };
~~~~ ^
1 warning generated.
~~~
https://godbolt.org/z/dMPxh53sq
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFVEuP2yAQ_jX4gmLZECebgw_JZvdWtaq25wibsU3FgpdH0uyv72Dvq6uo6kNVbbBhZhi--WagsfJc3w3KUz_YqCVtgGrohSbsmnplWiDFnhTbw80R3Jkqo4ISWj2Co60W0QPFpaTaeXiIgNbJQWcdkGpP2NUQwugJ3xJ2iw1M3o6jgw5cMs1be4_SE3YU41cL00fRQzI9Cn2wToIjbEOFubhzGESgndXanjxVAU1QBLRxAnEs0oKFVj7kB_o3UJKLw8vuIihrENPMClnfPLV5yjgypqMESvi1sj44EPeEP6mVCfReKFx-laIi690sp_gkXYM8ciQOF--TlpYpCUlaTFL2RlK-SNByT_gbVz7IFCfftjaGBATbGy_znLD13F_V5c_VLKX0eZ-05yUG2kTcIih5pg5G68JE-UWuqh169jY6LDFkiG85drbCDz0JZ5Tp0_BuSPXYBWpHcMJIarsEDCNP8LD2BO2FazBVFEsmQqrFGYQwQp-xWhYtlmP-xUjolAG5U0a488fkLVj3GXzUIUX2LzLx_nmlYH2DQH-BCWMD_AkN_zei8jmDtAeTiAaZXyyCHw9lb2Vjdcit63H2iF1--PRtqLh_yGTN5YZvRBZU0FDfCo0XwGg9Hssj0N_OOD2pMEx3Ck3nO4tO1-_AoEFsni4GrY_Pv8Xo7FdoA06V9xE8DqrlpiyyoS6gLQopRQXLatWUbNkVq1XX4Z-VDedFpkUD2tcp44wZONHJBY6R8UzVrGCsWJb48k11lUvgrdwIzlpoVpJXZFkA3h86TzgSS5mrJ0hN7D0qUyT-VSm8V70BmLZD_yKGwbq6HRy2xRxfNgGopwC-A4C3wR8">