[clang-tools-extra] [clang-tidy] ignore uninitialized std::array in member init (PR #98134)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 9 02:07:25 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tidy
@llvm/pr-subscribers-clang-tools-extra
Author: None (dsiroky)
<details>
<summary>Changes</summary>
cppcoreguidelines-pro-type-member-init check has an option IgnoreArrays for ignoring uninitialized C arrays. This patch adds support for C++ std::array as well.
---
Full diff: https://github.com/llvm/llvm-project/pull/98134.diff
1 Files Affected:
- (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp (+23-1)
``````````diff
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
index 9c3c7cc70c187..f5fa340cdb985 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -422,6 +422,28 @@ static const char *getInitializer(QualType QT, bool UseAssignment) {
}
}
+static bool isStdArray(QualType QT) {
+ const auto *RT = QT->getAs<RecordType>();
+ if (!RT)
+ return false;
+ const auto *RD = RT->getDecl();
+ if (!RD)
+ return false;
+
+ const IdentifierInfo *II = RD->getIdentifier();
+ if (!II)
+ return false;
+
+ if (II->getName() == "array") {
+ const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(RD->getDeclContext());
+ if (NS && NS->getName() == "std") {
+ return true;
+ }
+ }
+
+ return false;
+}
+
void ProTypeMemberInitCheck::checkMissingMemberInitializer(
ASTContext &Context, const CXXRecordDecl &ClassDecl,
const CXXConstructorDecl *Ctor) {
@@ -435,7 +457,7 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
bool AnyMemberHasInitPerUnion = false;
forEachFieldWithFilter(ClassDecl, ClassDecl.fields(),
AnyMemberHasInitPerUnion, [&](const FieldDecl *F) {
- if (IgnoreArrays && F->getType()->isArrayType())
+ if (IgnoreArrays && (F->getType()->isArrayType() || isStdArray(F->getType())))
return;
if (F->hasInClassInitializer() && F->getParent()->isUnion()) {
AnyMemberHasInitPerUnion = true;
``````````
</details>
https://github.com/llvm/llvm-project/pull/98134
More information about the cfe-commits
mailing list