================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits