[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


================
@@ -0,0 +1,146 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wconditional-scope -DTEST_1 %s
----------------
erichkeane wrote:

These tests aren't particularly great or varied, try your situations but also try to make them 'flow' a bit to show you've covered everything.  Make sure you cover more than just pointer cases.

Also, try some tests in a dependent case, where the variable itself is dependent.


also-also: What about an unevaluated context?  Or a situation where you don't actually take the variable?  Should THAT warn?

Consider:

```
if (auto x = bar()) {
}
else {
   decltype(x) f = g; // should this warn?
}
```


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


More information about the cfe-commits mailing list