[clang-tidy] New check: bugprone-empty-for-init
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
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++)`
Contributor guide
Assessment
This issue has not been assessed yet.