[clang] [Clang] FunctionEffects: accept throw-only callees from noexcept callers (PR #238401)
Doug Wyatt via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 4 11:05:21 PST 2026
================
@@ -88,12 +88,17 @@ struct Violation {
SourceLocation Loc;
const Decl *Callee =
nullptr; // Only valid for ViolationIDs Calls{Decl,Expr}WithoutEffect.
+ // True if the violation is, or is solely due to, an exception which
+ // propagates out of the function uncaught. A noexcept caller turns such an
+ // exception into termination, so it need not treat the callee as unsafe.
+ bool ThrowOnly = false;
----------------
dougsonos wrote:
After discussing this change with a colleague the other day, I searched for Herb Sutter's writings on exception specifications, which IIUC could be summarized as:
- recommends avoiding the old `throws(X)` specifications
- recommends `noexcept` when throwing is impossible or unacceptable (CPP Core guidelines)
- proposes a `throws` function annotation, with values returned through a statically allocated mechanism, so that code can keep using exception-style error handling without the cost (P0709, "Zero-overhead deterministic exceptions: Throwing values")
I came across P0709 when trying to understand if there ever could be a non-allocating way to throw and catch exceptions.
So I think tracking "throws" as a function effect could be an interesting direction, as long as we don't try to use it with the old exception specifications. I'll tinker with this; it messes a bit with some of the assumptions in the function effect analysis, but that's often a price of progress :)
https://github.com/llvm/llvm-project/pull/238401
More information about the cfe-commits
mailing list