================
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "RedundantZeroInitializerCheck.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/SourceManager.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+namespace {
+// Matches an initializer list written as ``{<single element>}``.
+AST_MATCHER(InitListExpr, isSingleElementBracedList) {
+ return Node.getLBraceLoc().isValid() && Node.getNumInits() == 1;
+}
+} // namespace
+
+void RedundantZeroInitializerCheck::registerMatchers(MatchFinder *Finder) {
+ Finder->addMatcher(
+ initListExpr(hasType(constantArrayType()), isSingleElementBracedList(),
+ hasInit(0, ignoringImplicit(integerLiteral(equals(0)))),
----------------
zeyi2 wrote:
```cpp
hasInit(0, ignoringParenImpCasts(integerLiteral(equals(0))))
```
So that we can handle:
```
int a[2] = {(0)};
double b[2] = {((0))};
```
Please also add this in regression tests.
https://github.com/llvm/llvm-project/pull/209367
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits