[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
Fri Oct 3 12:17:47 PDT 2025


================
@@ -2371,6 +2371,24 @@ NonOdrUseReason Sema::getNonOdrUseReasonInCurrentContext(ValueDecl *D) {
   return NOUR_None;
 }
 
+bool Sema::isConditionVarReference(const DeclRefExpr *DRE) {
+  if (!DRE)
+    return false;
+
+  const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl());
+
+  if (!VD)
+    return false;
+
+  for (Scope *S = getCurScope(); S; S = S->getParent()) {
+    if (VarDecl *CV = S->getConditionVar())
+      if (VD == CV)
----------------
erichkeane wrote:

I think we should still use `isSameEntity`, and we should probably figure out why that doesn't work.  If it doesn't, I have some concerns about this.

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


More information about the cfe-commits mailing list