[clang] [clang][Sema] Diagnose exceptions only in non-dependent context in discarded `try/catch/throw` blocks (PR #139859)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 19 06:28:58 PDT 2025
cor3ntin wrote:
In C++26, exceptions are allowed in a constant evaluated context, which is used extensively by reflection and maybe P2300. I also think allowing `try` not to be a keyword in some modes would harm the ecosystem.
Here is an interesting scenario
```cpp
constexpr void g() {
throw 42;
}
constexpr int f() {
try {g(); } catch {}
return 0;
}
```
static_assert(f() == 0); // the call to g() from here should be allowed
int main() {
return f(); // but not here if we want to disallow exceptions
}
```
So, now that I think about it, doing it at code gen is the only solution post C++26
https://github.com/llvm/llvm-project/pull/139859
More information about the cfe-commits
mailing list