<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/75940>75940</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang generates invalid code and leaks resource when throwing an exception after return statement
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
CurTInq
</td>
</tr>
</table>
<pre>
To be fair, all the other major compilers (gcc and msvc) also generate incorrect code according to the C++ standard, however clang also produces memory leak (destructor for returned statement was never called).
It seems like something similar being reported in #61900 but in context of coroutines, while it seems to be a more common case.
Minimal reproducible example (I literally took it from [the C++ standard](https://timsong-cpp.github.io/cppwp/n4659/except.ctor#2)): https://godbolt.org/z/Wvfz4jPW7
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxskk9r5DgQxT-NfCnSuMvuPz74kD8YcljYw8CcZanaViKpvFK5O5lPv8idMOwyYCwKxHv1nn46ZzdFol4dntThpdKrzJz65zX9eI3_VCPbz_4Hw0hw0S4pfAbtPchMwDJTgqDfOIHhsDhPKYPC82QM6Ggh5KtR2IH2mWGiSEkLgYuGUyIjYNgSaGM4WRcnEN5knxU-KXyCLDpanWyxnPlGV0pgvI7TXW9JbFdDGQIFTp_gSb8Xc0tZ0mqEE1w4QSJZUyRb5IQCRYGbzhDvctp7sgq7napfVP34KpCJQgbv3gkyB5K5bJZdcF4nGKlMiRZOQhZcBIXNcd_VNYyrlNlwFPoQ4AsYTryKi5RLgtvsPIH7NpCtUQ2BE5XyAkcwOtPXIvf_Xy66oH0x3MK60RPQhw6LpxL1FbwTStr7TxDm9yJ_SRxAHZ7-2OThReF5Flmyah4VDgoHcSFznB7MsuwmJ_M67hwrHMyy3BaFQ2yPh07hQB-GFtmVXhU2qLArX_MI_5Wb2I7sZcdpUjj8Ujj8vF5-tW9__zxVtm9s13S6on5_qrHrzseuq-Z-JHscRzqQ7UZrztg1rW2wbms8jee9bivXY43NHvfd_rDfN92OsDWnC9Z4PJ7wgqTamoJ2fuf9NRTvyuW8Un86dG1deT2SzxvfiBtBCrGgnvpy_2Fcp6za2rss-beCOPHUP2_AfbObwcWr9s5-oRvthl2GRJnXZAhuM0WQOfGtkKIj3HtzHEFfhL55_E1jtSbf_6_D-zMYDgqHss_X8bAkfiMjCoctXlY4bAn_DQAA___9dULr">