[clang-tools-extra] [clang-tidy] Fix readability-simplify-boolean-expr for init statements (PR #172220)

via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 14 17:59:43 PST 2025


https://github.com/zeyi2 requested changes to this pull request.

Sorry that I didn't have the condition to compile the code locally, so you may need to verify this on your side.

---

I think removing the `hasInitStorage()` check will cause the existing Fix-it logic to generate broken code. IMO the current implementation deletes the initialization statement:

```cpp
if (int x = val; true) {
    return x;
}
```
With this patch, Clang-Tidy will suggest replacing it with:

```cpp
{
    return x; // invalid code gen
}
```

So I think updating the replacement logic is necessary. (e.g. in `replaceWithThen/ElseStatement`, check `getInit()` then extract its source text)

Also, it may be reasonable to wrap the replacement in a new scope to preserve variable lifetimes.

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


More information about the cfe-commits mailing list