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

    <tr>
        <th>Summary</th>
        <td>
            Clang doesn't expand lifetime of a backing array for initilizer_list created in a compound literal and bound to const reference
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          igor-anferov
      </td>
    </tr>
</table>

<pre>
    The minimal reproducer showing the difference between GCC (correct behaviour) and Clang is the following:
```c++
#include <iostream>

struct S {
    S() { std::cout << __PRETTY_FUNCTION__ << std::endl; }
    ~S() { std::cout << __PRETTY_FUNCTION__ << std::endl; }
};

int main() {
    auto&& var = (std::initializer_list<S>){{}};
    std::cout << "=========================" << std::endl;
}
```
https://godbolt.org/z/a5MjqYTPW

This bug is easy to trigger accidentally when iterating over compound-literal-created initializer list in range-based for loop:
```c++
#include <iostream>

int main() {
    for (const auto& n: (std::initializer_list<int>){1, 2, 3, 4, 5})
        std::cout << n << '\n';
}
```
https://godbolt.org/z/PjPKnhvPq

Address Sanitizer reports stack-use-after-scope for this example. If objects aren't trivial, we'll be iterating over destroyed objects in the best case or over corrupted memory in the worst case.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0lcGO2zYTx5-GugxsyKRkrQ46rO34Q_ChqdF1UeRkUORI4oYiFZKy4xz67AVlr-0GTXtoChCULZIznP_8ZsS9V61BrEi-Ivkm4WPorKtUa92MmwadPSa1ledq3yH0yqiea3A4OCtHgQ58Z0_KtBA6BKmaBh0agVBjOCEa-N96DYQ-CescigA1dvyo7OgILYEbCWvNTQvKT-cbq_VkjbBnkm5I-kyW6WUIQldxXN5SpozQo0QgbK2sDw55T9i76_I0--BGEeAFSHE9BgDwQuhT9E2KFfggoyP2LOwYoiXC1nA47H55t99_PGx__bDev__5w-HwtnTbj0ZqwlZA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