[clang-tools-extra] [clang-tidy] Fix `cppcoreguidelines-pro-type-member-init` check (PR #169832)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 2 12:06:11 PST 2025
================
@@ -582,6 +583,33 @@ void ProTypeMemberInitCheck::checkMissingBaseClassInitializer(
void ProTypeMemberInitCheck::checkUninitializedTrivialType(
const ASTContext &Context, const VarDecl *Var) {
+ // Verify that the record actually needs initialization
+ const CXXRecordDecl *Record = Var->getType()->getAsCXXRecordDecl();
+ if (!Record)
+ return;
+
+ SmallPtrSet<const FieldDecl *, 16> FieldsToInit;
+ bool AnyMemberHasInitPerUnion = false;
+ forEachFieldWithFilter(
+ *Record, Record->fields(), AnyMemberHasInitPerUnion,
+ [&](const FieldDecl *F) {
+ if (IgnoreArrays && F->getType()->isArrayType())
+ return;
+ if (F->hasInClassInitializer() && F->getParent()->isUnion()) {
+ AnyMemberHasInitPerUnion = true;
+ removeFieldInitialized(F, FieldsToInit);
+ }
+ if (!F->hasInClassInitializer() &&
+ utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
+ Context) &&
+ !isEmpty(Context, F->getType()) && !F->isUnnamedBitField() &&
+ !AnyMemberHasInitPerUnion)
+ FieldsToInit.insert(F);
+ });
+
+ if (FieldsToInit.empty())
+ return;
----------------
vbvictor wrote:
Was this part purely copypasted from `checkMissingMemberInitializer`?
If so, can we refactor it into a helper function to avoid duplication
https://github.com/llvm/llvm-project/pull/169832
More information about the cfe-commits
mailing list