<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/104734>104734</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
FR: Have -fno-exceptions cause noexcept operator/std::is_nothrow_...() to treat functions as if they were non-throwing
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
pkasting
</td>
</tr>
</table>
<pre>
Chromium compiles (everything, including the STL) with `-fno-exceptions`. However, tests like the `noexcept` operator or `std::is_nothrow_move_constructible<>()` still treat functions as potentially-throwing unless they are explicitly marked `noexcept`. This means authors must still mark various places (e.g. move constructors of objects potentially stored in vectors) as `noexcept` to avoid potential pessimizations.
I believe it's also potentially pessimizing to blindly mark every function as `noexcept`, especially if functions we author call into third-party code not so marked; IIRC, the compiler has to emit code to handle potential exceptions from such code? When I discussed this a few years ago with some LLVM person (I forget who), I think this was a reason that we wouldn't want `-fno-exceptions` to actually compile code equivalent to if the coder had written `noexcept` on every declaration. (Sorry, memory is fuzzy; I just remember there was a good reason to not do "the simple thing" here.)
One possible way to have our cake and eat it too would be to have `-fno-exceptions` cause the `noexcept` operator, along with builtins like `__is_nothrow_constructible()` (which I think are what libc++ implements the STL in terms of), always claim that functions so queried were, indeed, non-throwing. Presumably this would lead to crashes or worse if code compiled this way was linked against a library not compiled this way; we'd be OK with that.
Hopefully, this would result in things like `constexpr if` fast-paths for non-throwing code always being taken, without the downsides of actually treating all contexts as `noexcept`, and without authors having to remember to so tag code.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VV9v2zgM_zTKC1HDtZO0echD212w4nbYYRvuHgvZomOtsuSJdFzv0x8ou2m7FffSBrBIkb9_0kT26BH3anOrNh9WeuA2xH3_qImtP66qYKb9XRtDZ4cO6tD11iGBKq7xhHHi1vqjKu7A-toNxvojcIvw9dsnVexgtNyC2uYXjQ8X-FRjz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