[clang] Suppress noreturn warning if last statement in a function is a throw (PR #145166)

Samarth Narang via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 25 07:15:37 PDT 2025


snarang181 wrote:

> > > I feel like this is a solution that can grow out of hand very easily. IMO the better solution would be to have `-Wmissing-noreturn` place a `[[noreturn]]` into the AST to avoid incorrect follow-up diagnostics.
> 
> > 
> 
> > I agree, in principle I would expect Clang to be able to prove (in simple cases) that a function cannot return, and then treat it as-if they were marked as `[[noreturn]]` in the source code, not just for purposes of diagnostics but also optimization. Suppressing the `-Wreturn-type` warning does not achieve that.
> 
> 
> 
> Actually, I just saw this and think it is a reasonably good idea.  Rather than trying to check the same functions over and over, we can 'cache' the answers via an implicit function attribute (only when one of the relevant diagnostics is enabled).  I'm not sure I would spell it `[[noreturn]]` even when implicit (as that could result in cascading diagnostics, and I'm not sure I want the optimization outcomes), but it would be generally more accurate.
> 
> 
> 
> Sorry for not seeing this sooner.

No issues. I will work on it further, thanks. 

https://github.com/llvm/llvm-project/pull/145166


More information about the cfe-commits mailing list