<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/110103>110103</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Diagnose dangling assignments for std::initializer_list.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend,
clang:memory-safety
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hokein
</td>
</tr>
</table>
<pre>
See the example below, it would be nice for clang to diagnose this case.
https://godbolt.org/z/W3dhEzY6M
```cpp
#include <vector>
using namespace std;
int main()
{
// Good: Initializing an initializer_list object from the array extends the
// lifetime of the array exactly like binding a reference to a temporary.
initializer_list<int> a = {1, 2, 3};
// Dangerous! the lifetime of the backing array is not extended for assignments.
//
// A holds dangling pointers into backing array which are destroyed at the end of full expression.
a = {2, 3, 4};
for (int i : a) {
i;
}
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxkU0FvtDYQ_TXmMsoK7F0IBw6bkK166KmHqqfK2ANMY2xkmySbX1-ZJcmWT0JG9tgzb968J0OgwSI27PTETm0mlzg634zuFclmndPX5k9EiCMCfshpNggdGvfO-DNQhHe3GA0dgiWF0DsPykg7QHSgSQ7WhfSWAigZ8MDyluXn2zrGOAcmzoxfGL8MTnfOxIPzA-OXT8Yvfwk9vnz-Xf5x_4iV-e1T87ydcEFWmUUjMPH8hio6z8TLLbgEsgNYOWGYpUIIUTPxdJ-QbIRJkmX8kfEatlC13QG4oYPfnNNMnOF3S5Gkoc-UV1qgrz36fwyFCK77F1WE3rtp5Ux6L6-AHxGtDulkl9hQj5EmBNf_775U0VzB0CtCR1av5cBjjx6twkSvhIjT7Lz0143XX9Aw8Uw2MvECEphogVVPRZobT4tgVbsj4xtVK-2A3i2B8WKFtYfZSfW6YlrhUgDr4tYl6lUGN11NaGM47LLvtmcYndEBtLSDSUlnRzaiD0A2ul2p95HUCNIjaAzRuytqkPEmT6sTvH4xBvBj9hgCOftd_JuCrXv-DMd7CmCFzfhjkgRBmrZcJfEjBgD6uZ7ebmppd-LMdCN0LWqZYVNUvBLHsjqKbGzUoyq0ElrjqdZYlzVHVWDZ6Vp0veqLjBqe82Ne87LIBefiUJ1UXVYVSl09qlIJdsxxkmQOxrxNyS0ZhbBgUxR5kYvMyA5NWL3M-epEJs69dzZNhvHU-l1gwsn560OQPcZrip7azDcp80O3DIEd86Si8FMrUjTYtF_G_p7Y3bBXFlefnZk47xV5yBZvmp31KY5Ld1BuYvySSm2_h9m7ZCbGL2uPgfHL1uZbw_8LAAD__zWRdr8">