[clang] [Sema] Diagnose use of if/else-if condition variable inside else-if/else branch(s) (PR #156436)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 30 06:19:35 PDT 2025


================
@@ -1570,6 +1564,12 @@ class Sema final : public SemaBase {
   Sema(const Sema &) = delete;
   void operator=(const Sema &) = delete;
 
+  /// Tracks condition variables declared in `if` statements,
+  /// mapping each VarDecl to the `Scope*` where it was created.
+  /// Used to detect references to these variables outside their
+  /// lifetime (e.g. in the `else` branch or after the `if`).
+  llvm::DenseMap<const VarDecl*, Scope*> IfScopeVars;
----------------
erichkeane wrote:

This shouldn't live in Sema, the Scope itself should have a reference to the var.

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


More information about the cfe-commits mailing list