[clang] [clang][Sema] Diagnose exceptions only in non-dependent context in discarded `try/catch/throw` blocks (PR #139859)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri May 16 06:33:17 PDT 2025
erichkeane wrote:
> Moving the checks does work for these limited cases, but now that we don't have them there, one of the old tests now doesn't show up the diagnosis:
>
> ```c++
> void f() {
> throw;
> }
>
> void g() {
> try {
> f();
> } catch (...) {
> }
> }
> ```
>
> Since there is a separate call:
>
> ```c++
> return Actions.ActOnCXXTryBlock(TryLoc, TryBlock.get(), Handlers);
> ```
>
> and debugging under lldb, breakpoints don't reach (i.e exit early) the transform calls.
Right, 'transform' only happens during template instantiation. So we need to find 'some place' (that is a seperate function) to do these diagnostics. I might suggest doing a new one, since there doesn't seem to be a sensible place to do so otherwise... perhaps something like:
```
void Sema::DiagnoseExceptionUse(bool isTry) {
// do the checking + diagnostic here, but have it check the decl-context for dependence
}
```
NOTE I had that return `void` instead of `bool`. (And is `Diagnose` instead of `Check`). I wonder if there is value to continuing (@AaronBallman??) and putting these in the AST anyway? The continued checking is perhaps valuable, and tooling might appreciate it in the AST anyway.
https://github.com/llvm/llvm-project/pull/139859
More information about the cfe-commits
mailing list