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

    <tr>
        <th>Summary</th>
        <td>
            lifetime extensions in default member initializers already supported?
        </td>
    </tr>

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

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

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

<pre>
    Consider the following snippet (https://godbolt.org/z/eMTeYba56):
```
struct A {
    A();
    ~A();
};

struct B {
    A&& a = {};
    void member();
};

void foo() {
    B b {};
    b.member();
}
```
Currently this emits the warning 
> warning: sorry, lifetime extension of temporary created by aggregate initialization using default member initializer is not supported; lifetime of temporary will end at the end of the full-expression [-Wdangling]

However as one can see from the generated assembly, the lifetime of the temporary create in the initializer of `B::a` correctly gets its lifetime extended to the lifetime of the `B` object (`~A()` is called after `member()`).

The reason for not supporting lifetime extensions in default member initializers is described in definition of the `PathLifetimeKind` enum:
> We should lifetime-extend, but we don't because (due to technical limitations) we can't. This happens for default member initializers, which we don't clone for every use, so we don't have a unique MaterializeTemporaryExpr to update.

But as one can see in an AST dump, the `MaterializeTemporaryExpr`, that is not getting cloned, already has its lifetime extended by the corresponding `FieldDecl` and thus doesn't need to be updated:
```
|-CXXRecordDecl <line:7:1, line:10:1> line:7:8 referenced struct B definition
| |-...
| |-FieldDecl <line:8:5, col:14> col:9 a 'A &&'
| | `-ExprWithCleanups <col:11, col:14> 'A':'A' xvalue
| |   `-MaterializeTemporaryExpr <col:11, col:14> 'A':'A' xvalue extended by Field 0x558dc5d85618 'a' 'A &&'
| |     `-CXXBindTemporaryExpr <col:11, col:14> 'A':'A' (CXXTemporary 0x558dc5d85ae0)
| |       `-CXXConstructExpr <col:11, col:14> 'A':'A' 'void ()' list
| |-...
```
I don't know if this covers all possible cases but at least in the simple example here the emitted warning is a lie.
</pre>
<img width="1px" height="1px" alt="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