<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/65282>65282</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Lifetime of temporaries within default member initializers of aggregates
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
leni536
</td>
</tr>
</table>
<pre>
version: clang 16.0.0
flags: `-std=c++20 -O2 -pedantic-errors`
Consider the following code:
```cpp
struct X {
X() noexcept;
~X();
};
struct A1 {
int i = (X(), 42);
};
struct A2 {
int i = (X(), 42);
int j = (X(), 42);
};
void foo() {
// The two objects of type X should have nested lifetimes
(A1{}, A1{});
}
void bar() {
// The two objects of type X should have nested lifetimes
A2{};
}
```
https://godbolt.org/z/f1YTdno83
### Observed behavior
In each of `foo` and `bar` two temporary objects of type `X` are created and destroyed. From the generated code it can be observed that the first object is created and destroyed before the second object is created and destroyed.
### Expected behavior
According to https://timsong-cpp.github.io/cppwp/n4868/intro.execution#5.6 and https://timsong-cpp.github.io/cppwp/n4868/intro.execution#5.sentence-4 the default member initializers are subexpressions of the full expressions `(A1{}, A1{})` and `A2{}`.
The temporaries that materialize within these subexpressions should live to the end of the full-expressions.
This means that in both cases that two objects of type `X` should have overlapping lifetimes.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VUFvpDgT_TXuS6mRMQ1NHzh0pj-kT1ppLnPIHo1dgEfGRrbpJHPY374y0AmdZHZXo10JJbTtevWq6j3DvVedQaxI_kDyy45Pobeu0mhUnhW7xsqX6orOK2tIdgahuekgLRKaUEIvhJ5bzTsft0hB9z5Ikl0EYQ-EPTAK-68M9iNKboISe3TOOk-KNXL5-8UaryQ6CD1Ca7W2T8p0IKxEkp23J2Pg_IhxXFZ8cJMI8Ajk-LCsAAA8ElYSdgJj8VngGEi22fxj3X1dJMfL2_sW9ZzewyoTQAHJLkBYeUN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