<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/85601>85601</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang fails to destroy temporaries bound to reference members by default member initializers at end of full-expression
</td>
</tr>
<tr>
<th>Labels</th>
<td>
c++14
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hubert-reinterpretcast
</td>
</tr>
</table>
<pre>
Clang appears to defer the destruction of temporaries bound to reference members by a default member initializer through aggregate initialization until the end of the block that the aggregate initialization appears in.
In the following program, `f()` and `g()` should have the same return value: The destructor for the `A` object in the evaluation of `g()` should occur at the end of the full-expression where the `B` temporary is created.
Online compiler link: https://godbolt.org/z/o9Ez3d7Ex
### SOURCE (`<stdin>`):
```cpp
struct A {
int &x;
constexpr ~A() { --x; }
};
struct B {
int &x;
const A &a = A{x};
};
constexpr int f() {
int x = 1;
{ B{x}; }
return x;
}
constexpr int g() {
int x = 1;
B{x};
return x;
}
static_assert(f() == g());
```
### COMPILER INVOCATION:
```
clang++ -fsyntax-only -std=c++20 -w -xc++ -
```
### EXPECTED OUTPUT:
Clean compile
### ACTUAL OUTPUT:
```
<stdin>:19:15: error: static assertion failed due to requirement 'f() == g()'
19 | static_assert(f() == g());
| ^~~~~~~~~~
<stdin>:19:19: note: expression evaluates to '0 == 1'
19 | static_assert(f() == g());
| ~~~~^~~~~~
1 error generated.
```
### COMPILER VERSION INFO (`clang++ -v`):
```
clang version 19.0.0git (https://github.com/llvm/llvm-project.git c0d03d28c58f3016eb25ce8d1160e11183d01735)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/wandbox/clang-head/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Candidate multilib: .;@m64
Selected multilib: .;@m64
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVk1v2zgQ_TX0ZSBDIm3JPvjgLy0CdOOiTYq9FZQ4krilSS9JJU4P_e0LSnLsuEmRAhUM26I4b97MPA2HOydrjbgg0xWZbka89Y2xi6Yt0PrIotQe7cGiL7nzo8KIp8VacV0DPxyQWwfegMAKLfgGQaDzti29NBpMBR73B2O5leigMK0WYbcNu1GXCHvcF2gdFE_AAwhvlR8WQWrpJVfye4dsTVs3wOvaYs09np_yzlWrvVQdAdSic9wgFMqU38A33He3bxqfApF6TOINiZf9943uzCqjlHmUuoaDNbXle0LXQNK4InRG6JykMXAtwkp9XnGNaZWAhj9gB-L4HsGib62GB65aJGwJdxf5MhYq06eQpPEyYJjiXyw9yJ4GBjN-yuur3kxZthaGaC_yULVKRXg8WHQu2D82aPHkahUATmV6AumgtMg9ihe52GklNUJp9gep0IKS-lsIofH-4AhbEpoTmtdGFEb5sbE1ofl3QnMz335nItseL8EIZf0HPu_uP623ECJJY8LWzgupCduGOzoPuL1BGvef8nDoV_qkwRJItupXAKT2QGh6JOx5qTTa-RA5_Fj26QoGEEVhE5BsM-Bnm2ejAXn1HuTgn6YcCNvAkmSr4yXQ5f8zjwBVnalcejh2OMmFk8B1dcY9E4aTlo4v3L3iq36vr9U1_1_5cJ57WX7lzqH1hM6eI2KbgHuSZijh6qqErwthvfv7482H7Se4uf2yWy_vbna3P1d_iC80H0JXhK4gqtyT9vwYGa2eIHJeELYp-4c0hugRomN52vsuItt_Pm7Xd9sN7O7vPt7fPZNYK-T6pP_XTZfru_vlh2vDa38XImfLJGg8mYY3Ca01Nvzpcwt9bsPrWnGpUIBosW-e_7XS4h47TWZvZT47FRGSUPw1_H7JoLuC7cuLTLc_TtfbQYUv0MZ3ne6i-Qx9DLtzg9AsPjFI_gzpn_l2PAfO_aakzzbUqNFe9rp3ivTL9tPnm90t3Nzmu6F5vVDlw1v960LB8IC2S0gyH8fjuJahnLOrfip90xbj0uwJzZV6OP1EB2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