[PATCH] D101239: Enable IgnoreArray flag in pro-type-member-init rule
Hana Joo via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 24 10:27:50 PDT 2021
h-joo created this revision.
h-joo added a reviewer: alexfh.
h-joo added a project: clang-tools-extra.
Herald added subscribers: kbarton, nemanjai.
h-joo requested review of this revision.
Herald added a subscriber: cfe-commits.
The flag used to exist but wasn't implemented. Fixes b/47288 <https://bugs.llvm.org/show_bug.cgi?id=47288>
https://reviews.llvm.org/D101239
Files:
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.ignorearrays.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.ignorearrays.cpp
===================================================================
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.ignorearrays.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s \
+// RUN: cppcoreguidelines-pro-type-member-init %t \
+// RUN: -config="{CheckOptions: \
+// RUN: [{key: cppcoreguidelines-pro-type-member-init.IgnoreArrays, value: 1} ]}"
+
+struct HasArrayMember {
+ HasArrayMember() {}
+ // CHECK-MESSAGES: warning: constructor does not initialize these fields: Number
+ int Array[4];
+ int Number;
+};
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -402,6 +402,8 @@
// 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) &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101239.340300.patch
Type: text/x-patch
Size: 1463 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210424/f596d1e7/attachment-0001.bin>
More information about the cfe-commits
mailing list