[clang-tools-extra] [clang-tidy] Add `readability-redundant-zero-initializer` (PR #209367)
Zeyi Xu via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 3 03:32:13 PDT 2026
https://github.com/zeyi2 commented:
For this case:
```cpp
#include <vector>
std::vector<int> make() {
return {0};
}
```
Currently the check would rewrite it to:
```cpp
std::vector<int> make() {
return {};
}
```
IMO there is a semantic change here.
By looking at the AST dump:
```
`-CXXConstructExpr 0x9e2d6d6d8 <col:10, col:12> 'std::vector<int>' 'void (initializer_list<value_type>)' list std::initializer_list
`-CXXStdInitializerListExpr 0x9e2d6d260 <col:10, col:12> 'initializer_list<value_type>':'std::initializer_list<int>'
`-MaterializeTemporaryExpr 0x9e2d6d248 <col:10, col:12> 'const value_type[1]' xvalue
`-InitListExpr 0x9e2d6d200 <col:10, col:12> 'const value_type[1]'
`-IntegerLiteral 0x9e2d6c270 <col:11> 'int' 0
```
I think we should also filter `cxxStdInitializerListExpr()` in the matcher, something like: `unless(hasAncestor(cxxStdInitializerListExpr()))`
https://github.com/llvm/llvm-project/pull/209367
More information about the cfe-commits
mailing list