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

    <tr>
        <th>Summary</th>
        <td>
            [C++] Mandatory copy elision with temporary lifetime extension with incorrect behavior
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          joaovitor72
      </td>
    </tr>
</table>

<pre>
    Suppose the following C++ code:

```
#include <iostream>

struct K
{
    K() { std::cout << "K::K()" << std::endl; }
    K(K const&) { std::cout << "K::K(K const&)" << std::endl; }
    K(K&&) { std::cout << "K::K(K&&)" << std::endl; }
    ~K() { std::cout << "K::~K()" << std::endl; }
};

struct B
{
    K const& l;
    ~B() { std::cout << "B::~B()" << std::endl; }
};

int main() {
    B b = B{ K{} };
    std::cout << "end of main" << std::endl;
    (void)b;
}
```
Under post-C++17 copy elision rule changes the temporary `K{}` should get its lifetime extended to match `B b` lifetime, this is not what currently happens.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyllM1uozAQx5_GXEaNHFMgOXAoSfcS7Wm1D2DwBFw5NrJNsnn7HRLyJbVSoyIL7PHM_H8zYGqnjuWfoe9dQIgdwtYZ4w7atrBioqIBjVPI0jfG14xf7jmfxnkpUm0bMygElq60C9Gj3LH0_T6GjEMTYTPZiuo8Abo2TCyYWAIZIUQ1iqVvjRvimI4GMCE2Z-vkSobL3jUArTIsrSjL-jH1hkqwITKRPyHyEPSc3CnmKa1rxLeFWPH-RNdu3t8SGCdp9cnLqz57eddGgblGTYjVNxCrK2L1I0RtI-yktjfJG0oFNaVcEz-BbMatYg33KUanrwBJG9x2yv0l2l3dYrF3WhFEfUO8cj-enL9WoQc6fPFlOm7zgvrZHwGNDtpZ8INBaDppWwynAxpx1zsv_REoy1QLzSB0bjAKWoygYwCjtxj1DgH_RUJEBdFRDbHpxjhqyBhzcWJiRbl1ABrWRTh0MkIzeI82miN0su_RhtmZOVFlqpbpUiZRR4Mly6qJnWVr-C2tktER3kMZBx27O_RHupsH_UYcqdKnVmMn99r5ZPCm7GLsw9hu8YtGS55DPWvcjhbG7C-Pl967D4qlpQ5hwECTLOfZIunKTBSZ5HLeyLTYqm2W8UXNlzU98XUhmnliZI0mjMVQFYkuBReC5_Ocp4KcZrVcCsW3dcHrXC1yZK8c6Ysws1F45nyb-PLEUA9toE0qO4bbpgxBtxbxkl8OsXO-_HDS7TV1qxDJCbk88f4HBnmH9w">