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

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 2 09:02:49 PDT 2025


================
@@ -13594,6 +13594,9 @@ def warn_acc_var_referenced_lacks_op
               "reference has no effect">,
       InGroup<DiagGroup<"openacc-var-lacks-operation">>,
       DefaultError;
+def warn_out_of_scope_var_usage
+    : Warning<"variable %0 used in else/else if block is out of scope">,
----------------
Alcaro wrote:

I'd vote no. The variable is declared in the if part of the if-statement, not in the else.

If you mean if/else-if, then I'd still vote no - else-if is not a thing in the C++ spec, it's just an if-statement whose statement-false is another if-statement (and the variable is still declared inside the if part). No need to be pedantic at the expense of conciseness.

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


More information about the cfe-commits mailing list