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

    <tr>
        <th>Summary</th>
        <td>
            Double-destruction (& double-construction) when statement-expression returns
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          higher-performance
      </td>
    </tr>
</table>

<pre>
    It seems #85398 hasn't been quite fixed. In some sense, I think commit 89ba7e183e6e2c64370ed1b963e54c06352211db actually made things worse, because we now get a double-destruction (which is more likely to cause a security issue) instead of neglecting to run a destructor (which would've been more likely to cause a leak instead).

[Repro](https://godbolt.org/z/obP9dxE4a):

```
#include <stdio.h>
struct D {
    ~D()              { printf("[%p] D::~D()\n" , this); }
    D()               { printf("[%p] D::D()\n" , this); }
    D(int x)          { printf("[%p] D::D(int %d)\n" , this, x); }
    D(D const &other) { printf("[%p] D::D(D const & %p)\n", this, &other); }
};
struct S { D d; int i; };
static S f() { return S{ D(1), ({ return S(); 0; }) }; }
int main() { return f().i; }
```
Clang (trunk):
```
[0x7ffdfbc4df68] D::D(int 1)
[0x7ffdfbc4df68] D::D()
[0x7ffdfbc4df68] D::~D()
[0x7ffdfbc4df68] D::~D()
```
Clang 18.1.0:
```
[0x7fffa42f9e60] D::D(int 1)
[0x7fffa42f9e60] D::D()
[0x7fffa42f9e60] D::~D()
```

Expected behavior: The `D(1)` subobject should be destroyed before `S()` constructs an object on top of it.

Actual behavior: The object is constructed twice at the same location, _then_ destroyed twice at the same location.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVUtv4zYQ_jX0ZRCBoqzXQYc4ioHciqb3BUWOLDYU6ZJU7PSwv72gZCfxrtO6axjyg_N937w4w71XO4PYkHxD8nbFpzBY1wxqN6C726PrrRu5EbjqrHxrngJ4xNEDYVmVZ3UFA_eGsDJAh2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