[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
Mon May 19 06:16:05 PDT 2025


erichkeane wrote:

>What are the use cases for disabling exceptions but still allowing the constructs in source? e.g., do we want to start disabling the keywords entirely, and thus they won't appear in the AST? Or do we want them to be a codegen-only option, at which point they do appear in the AST and we only diagnose at CodeGen time (which is also inconsistent with GCC)? Or do we want to do whatever GCC does? (Note, Clang has -fcxx-exceptions and GCC does not, so we're already somewhat inconsistent between the two compilers.)

Yep, thats the question :)  I think the 1st one (ignoring the construct entirely/stop trying to parse it at all/etc) is a worse experience, and inconsistent with history.  AND I wouldn't want people to have a C++ code dialect where they can use 'try' as a variable name.

I don't think we should diagnose at CODEGEN time.  I'm suggesting diagnosing them at 'non-dependent/non-discarded' time, but putting them in the AST anyway.  This will inhibit codegen, but would mean tooling would be able to see them anyway.  WHICH they'll have to do for dependent contexts anyway with the change.

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


More information about the cfe-commits mailing list