Issue 177181
Summary [clang-tidy] New check: bugprone-empty-for-init
Labels clang-tidy
Assignees
Reporter Adel-gid
    I am requesting a new check (warning) that detects `for` loops with an empty initialization statement.

**Detection Logic :**
The check should flag any `for` loop where the initialization clause is missing.
Essentially, it should target the AST equivalent of the regex `r"for[ \t]*(;"`.

**Rationale :**
In my analysis of a 500KB C89 codebase, I identified 87 instances of this pattern.
Each instance represents a potential "audit blocker" or a logical error where an induction variable carries over "stale" state from a previous scope without explicit re-initialization.

**Desired Behavior :**
The tool should emit a **warning** for code like this:
```c
int i = 0;
// ...
for (; i < 16; i++) { ... } // <--- WARNING: Empty initialization
```

**Silence Options :**
It would be beneficial to allow silencing this warning via explicit intent, such as a comment in the init block:
`for (/* cont */; i < 16; i++)`
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to