From: Hana Joo Date: Wed, 12 May 2021 11:57:17 +0000 (+0100) Subject: [clang-tidy] Enable the use of IgnoreArray flag in pro-type-member-init rule X-Git-Tag: llvmorg-14-init~6935 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=163325086c35b3984c5e6f7a2adb6022003fcd84;p=platform%2Fupstream%2Fllvm.git [clang-tidy] Enable the use of IgnoreArray flag in pro-type-member-init rule 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 --- diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp index f446836..43812fe 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp @@ -402,6 +402,8 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer( // Gather all fields (direct and indirect) that need to be initialized. SmallPtrSet 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 index 0000000..1b52608 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.ignorearrays.cpp @@ -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; +};