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

    <tr>
        <th>Summary</th>
        <td>
            `bugprone-exception-escape` reported for generic code with `libc++`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc++,
            clang-tidy
      </td>
    </tr>

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

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

<pre>
    ```cpp
#include <functional>

struct OnExit {
    std::function<void()> f;

 ~OnExit() {
        f();
 }
};
```

```
<source>:6:5: warning: an exception may be thrown in function '~OnExit' which should not throw exceptions [bugprone-exception-escape]
    6 |     ~OnExit() {
      | ^
```

https://godbolt.org/z/PG8M7jeE9

This is reported for any file which includes it (even when unused) when using `libc++`. There is no warning with `libstdc++`.

First I think this should only be reported when it is used. And second as you cannot annotate the function with `noexcept` it should only be reported when the provided function does not throw an exception.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VM3O4zYMfBr6QiRwpNiODz7kt-ihaA_7ArJE29rqkwxJTjY99NkLJfEX7wL9AkFJCHI4wyEkQtC9JWqgOEBxysQUB-ebTnu6iStlrVP3Bsr8eeQ4Qn6CfA-MayvNpAiBH7vJyqidFQb4-ZXwuEP0k4z4pz3_0BGhOjzDiIghKuB74Pu5GPjx6rQCtgNWAz9jB_ywBMN_nzjPjJ_R0qebS-c4VKdXfXV6Y81altC_BvkxuMlLSnL4vgS-L4Dv8Sa81bZPP4VF-iFpTMzxQ9yxJYyDdzeL2uKsCYFVn6wrvA1aDhgGNxmF1sVnxRsoIBSHdupH7yytPsMrClKMBMXpLbhEqI4P2V9OJSVBcf5C-hDjGJIT7ALs0jvVOhPXzvfALv8Au_z12-6P6jud62XRt0EH1AE9jc5HUtg5j8LesdOGXjJf-xEwOc92dCWLt4EsTnYKpBLZ59-gbY9Q5ka3EtghnTJf47eBPKUm1s2Dx5uOwys1RLXIXpK7aB8i_o5x0PbvdId55M6ah1GftB8EdExdEqc17q3CQNJZhSLg3U0ohU1OPW4Rk8n0tnfmY93TLCjzBPdluwQwenfVKs1tRlKOwmIlluu1zlTDVc1rkVGzqViV802xqbKhqZlQbNMxlYtKqa6uCk71ZseoKrd1rVimG5azbV4zttkVO16t2bau5a5uK57XW6pL2Ob0IbRZG3P9SK5nOoSJmk1eF7sqM6IlEx5vA2MLfxgDdgTGpBG2X0Wt7ilUnDLfJKBVO_UBtrnRIYY3dNTRUHpM_n_Fy_znnerJktcSpVO0dP9tfTZ50_yyxDoOU7uW7gPYJXV_fa1G776TjMAuD5UB2OUl9Nqw_wIAAP__i_eKhQ">