@@ -124,6 +124,28 @@ static bool isVclTypeInit(const Type *type)
124124 return false ;
125125}
126126
127+ // Plain old C struct?
128+ static bool isPodStruct (const Scope *scope) {
129+ if (scope->type != Scope::ScopeType::eStruct && scope->type != Scope::ScopeType::eUnion)
130+ return false ;
131+ if (!scope->functionList .empty ())
132+ return false ;
133+ for (const Variable& var: scope->varlist ) {
134+ if (!var.valueType ())
135+ return false ;
136+ if (var.valueType ()->isIntegral () || var.valueType ()->pointer || var.valueType ()->isFloat ())
137+ continue ;
138+ if (var.valueType ()->typeScope && isPodStruct (var.valueType ()->typeScope ))
139+ continue ;
140+ return false ;
141+ }
142+ for (const Scope* childScope: scope->nestedList ) {
143+ if (!isPodStruct (childScope))
144+ return false ;
145+ }
146+ return true ;
147+ }
148+
127149// ---------------------------------------------------------------------------
128150
129151CheckClass::CheckClass (const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
@@ -298,17 +320,30 @@ void CheckClass::constructors()
298320 const Scope *varType = var.typeScope ();
299321 if (!varType || varType->type != Scope::eUnion) {
300322 const bool derived = scope != var.scope ();
323+ // is the derived variable declared in a plain old C struct
324+ bool varScopeIsPodStruct = false ;
325+ if (derived && scope->definedType && scope->definedType ->derivedFrom .size () > 0 ) {
326+ for (const Scope* s = var.scope (); s; s = s ? s->nestedIn : nullptr ) {
327+ for (const Type::BaseInfo& baseInfo: scope->definedType ->derivedFrom ) {
328+ if (s->definedType == baseInfo.type ) {
329+ varScopeIsPodStruct = isPodStruct (s);
330+ s = nullptr ;
331+ break ;
332+ }
333+ }
334+ }
335+ }
301336 if (func.type == Function::eConstructor &&
302337 func.nestedIn && (func.nestedIn ->numConstructors - func.nestedIn ->numCopyOrMoveConstructors ) > 1 &&
303338 func.argCount () == 0 && func.functionScope &&
304339 func.arg && func.arg ->link ()->next () == func.functionScope ->bodyStart &&
305340 func.functionScope ->bodyStart ->link () == func.functionScope ->bodyStart ->next ()) {
306341 // don't warn about user defined default constructor when there are other constructors
307- if (printInconclusive)
342+ if (printInconclusive && (!derived || !varScopeIsPodStruct) )
308343 uninitVarError (func.token , func.access == AccessControl::Private, func.type , var.scope ()->className , var.name (), derived, true );
309344 } else if (missingCopy)
310345 missingMemberCopyError (func.token , func.type , var.scope ()->className , var.name ());
311- else
346+ else if (!derived || !varScopeIsPodStruct)
312347 uninitVarError (func.token , func.access == AccessControl::Private, func.type , var.scope ()->className , var.name (), derived, false );
313348 }
314349 }
0 commit comments