================
@@ -971,6 +971,32 @@ StmtResult Sema::ActOnIfStmt(SourceLocation IfLoc,
   if (!ConstevalOrNegatedConsteval && !elseStmt)
     DiagnoseEmptyStmtBody(RParenLoc, thenStmt, diag::warn_empty_if_body);
 
+  // Checks for if condition variable usage in else scope
+  if (elseStmt) {
+    VarDecl *ConditionVar = dyn_cast_if_present<VarDecl>(Cond.get().first);
+
+    if (ConditionVar) {
+      struct ElseVariableUsageChecker
----------------
erichkeane wrote:

I mentioned a few times, we shouldn't be using the recursive ast visitor.  
`Scope` can store the variables in the stack on an `if` and check those.  Also, 
since this is so costly, we shouldn't be doing it unless th e diagnostic is 
enabled.

https://github.com/llvm/llvm-project/pull/156436
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to