================
@@ -0,0 +1,110 @@
+// RUN: %check_clang_tidy -std=c++14-or-later %s 
modernize-redundant-zero-initializer %t
+
+char a[12] = {0};
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: redundant zero initializer; 
replace with empty braces [modernize-redundant-zero-initializer]
+// CHECK-FIXES: char a[12] = {};
+
+int b[5] = {0};
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant zero initializer; 
replace with empty braces
+// CHECK-FIXES: int b[5] = {};
+
+double d[3] = {0};
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: redundant zero initializer; 
replace with empty braces
+// CHECK-FIXES: double d[3] = {};
+
+void *p[4] = {0};
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: redundant zero initializer; 
replace with empty braces
+// CHECK-FIXES: void *p[4] = {};
+
+char one[1] = {0};
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: redundant zero initializer; 
replace with empty braces
+// CHECK-FIXES: char one[1] = {};
+
+const char cq[8] = {0};
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: redundant zero initializer; 
replace with empty braces
+// CHECK-FIXES: const char cq[8] = {};
+
+int spaced[2] = { 0 };
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: redundant zero initializer; 
replace with empty braces
+// CHECK-FIXES: int spaced[2] = {};
+
+int trailingComma[3] = {0,};
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: redundant zero initializer; 
replace with empty braces
+// CHECK-FIXES: int trailingComma[3] = {};
+
+int paren[2] = {(0)};
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: redundant zero initializer; 
replace with empty braces
+// CHECK-FIXES: int paren[2] = {};
+
+double nestedParen[2] = {((0))};
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: redundant zero initializer; 
replace with empty braces
+// CHECK-FIXES: double nestedParen[2] = {};
+
+struct S {
+  char buf[4] = {0};
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: redundant zero initializer; 
replace with empty braces
+  // CHECK-FIXES: char buf[4] = {};
+};
+
+void localVariables() {
+  int local[4] = {0};
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: redundant zero initializer; 
replace with empty braces
+  // CHECK-FIXES: int local[4] = {};
+  static int staticLocal[2] = {0};
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: redundant zero initializer; 
replace with empty braces
+  // CHECK-FIXES: static int staticLocal[2] = {};
+}
+
+// Negatives.
+
+char emptyBraces[12] = {};
+int nonZero[3] = {1};
+int multiZero[3] = {0, 0};
+int mixed[4] = {0, 5};
+int noInit[3];
+
+// Multi-dimensional arrays without inner braces: the single `0` initializes a
+// subobject through brace elision, so there is no written single-element `{0}`
+// list to rewrite.
+int twoD[2][3] = {0};
+int oneByOne[1][1] = {0};
+int rowVector[1][3] = {0};
+int columnVector[3][1] = {0};
+
+// The array bound is deduced from the initializer; `{}` would change the size.
+char deduced[] = {0};
+
+// Zero written in a form other than the integer literal `0`.
+char nullChar[4] = {'\0'};
+double zeroDouble[3] = {0.0};
+void *nullPtr[4] = {nullptr};
+
+// Not an array.
----------------
vbvictor wrote:

ditto

https://github.com/llvm/llvm-project/pull/209367
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to