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

    <tr>
        <th>Summary</th>
        <td>
            Exceptions constructed from std::string bypass catch handlers on Clang 18
        </td>
    </tr>

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

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

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

<pre>
    Exceptions constructed from an `std::string` bypass catch handlers and terminate the program. The same exception constructed from a string literal behaves normally. The following program compiled with Clang 14 catches both exceptions. However, on Clang 18 the "dynamic" version terminates the program with the following message:

> libc++abi: terminating due to uncaught exception of type std::runtime_error: dynamic

```
// clang++ -std=c++20
#include <iostream>
#include <stdexcept>
#include <string>

void literal() {
  throw std::runtime_error("literal");
}

void dynamic() {
  throw std::runtime_error(std::string("dynamic"));
}

int main() {
 for (auto f : {literal, dynamic}) {
    try {
      f();
    } catch (std::runtime_error e) {
      std::cerr << "caught: " << e.what() << std::endl;
    }
  }
}
```

Working compiler:
  * Apple clang version 14.0.3 (clang-1403.0.22.14.1)
  * Target: arm64-apple-darwin22.5.0
  * Thread model: posix

Compiler that fails:
  * Homebrew clang version 18.1.6
  * Target: arm64-apple-darwin22.5.0
  * Thread model: posix
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVd2O6yYQfhpyM4plD46zvvDFJjnReYAj9bLCZmLTYrAAJ5u3r7ATJ5s9W6lSpRUbw_D9MDMgvFetIarYZsc2h5UYQ2ddJTR9CCPJNd3ohLHnVW3ltfrx0dAQlDUeGmt8cGMTSMLJ2R6EAVakPkjG3xl_98Ep07Iihfo6CO-hEaHpoBNGanIehJEQyPXKiEAQOoLB2daJPoFfHYEXPQHd6X7DBjMBaBXICQ01deJMHox1vdD6OsOcrNb2EuNu6NDYflCaJFxU6GCvhWkhy2d15KG2oXvw-gR-2gudyTHcgzX3-LdJMEOUVyN61TBEOJPzUepiyj-7munCJ0k9eS9aiueVHlh6H_kP0KpuGO4Y7kStGH9fQOM2ORIEC6NpxNh24emU7AnCdSBYkuBGE1RPf5Jz1kWcu95nviK9_c2feGR4hCYanSXAesI73BThEsiVafQoCRjfK-uDI9Ez_uN3yz7IWea361O1LIvTeLZK3vPL8I1hCWy7m9cAQufs5TurMRqXrciwZPy2k20PX0iWNP5Hktdqn2gfNRFpv2dWJkAvlPnCerIOGL6JMVg4QUwb2-4WM_tF7fbwohYguOvnCYDTjL-oiHNse7j147OJT-6AvoDD4yAaci7mjfF9bIO5EieliPd5Si6dCHd389wCQEbqV0n3j8c5LT9eanQa_7Du79gPt452Sx8BMHyH92HQNNfx0ptZnqQJj6an-XWWpzxJE8Qky5MsntITwC_hWppMCdcX-VpEwLUU7qIMYrJJ0k_RnSMhobeSdNwzWK8-nuXubzIhdCLASSjtXxT_tD3Vji6vot-SLCn-Z2UrWXFZ8lKsqMq22TbfFCWWq64qSp43WV3jFsWGUo6FqN_yoqzrMk0x4ytVYYp5WqQcOWJaJiVPN02GNefbTBI_sTylXiidaH3uE-valfJ-pKrMscSVFjVpPz03iLdbBuPL46oYv67H1rM81coH_0AIKmj61-fnpRW_eXWervDV6HTVhTBMaZhuvVaFbqyTxvYMj5H79m89OPsXNYHhcbLiGR5nN-cK_wkAAP___IwypQ">