[clang-tidy] Enable the use of IgnoreArray flag in pro-type-member-init rule
authorHana Joo <hanajoo@google.com>
Wed, 12 May 2021 11:57:17 +0000 (12:57 +0100)
committerNathan James <n.james93@hotmail.co.uk>
Wed, 12 May 2021 11:57:21 +0000 (12:57 +0100)
The `IgnoreArray` flag was not used before while running the rule. Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=47288 | b/47288 ]]

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D101239

clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.ignorearrays.cpp [new file with mode: 0644]

index f446836..43812fe 100644 (file)
@@ -402,6 +402,8 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
   // Gather all fields (direct and indirect) that need to be initialized.
   SmallPtrSet<const FieldDecl *, 16> FieldsToInit;
   forEachField(ClassDecl, ClassDecl.fields(), [&](const FieldDecl *F) {
+    if (IgnoreArrays && F->getType()->isArrayType())
+      return;
     if (!F->hasInClassInitializer() &&
         utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
                                                             Context) &&
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.ignorearrays.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.ignorearrays.cpp
new file mode 100644 (file)
index 0000000..1b52608
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: %check_clang_tidy %s \
+// RUN: cppcoreguidelines-pro-type-member-init %t \
+// RUN: -config="{CheckOptions: \
+// RUN: [{key: cppcoreguidelines-pro-type-member-init.IgnoreArrays, value: true} ]}"
+
+typedef int TypedefArray[4];
+using UsingArray = int[4];
+
+struct HasArrayMember {
+  HasArrayMember() {}
+  // CHECK-MESSAGES: warning: constructor does not initialize these fields: Number
+  UsingArray U;
+  TypedefArray T;
+  int RawArray[4];
+  int Number;
+};