@@ -1153,6 +1153,27 @@ static bool astIsRhs(const Token *tok)
11531153 return tok && tok->astParent () && tok == tok->astParent ()->astOperand2 ();
11541154}
11551155
1156+ // does the destructor of the pointed-to class read members that are not initialized by default?
1157+ static bool isDataReadInDestructor (const ValueType* vt, const Library& library)
1158+ {
1159+ if (!vt || vt->pointer != 1 || !vt->typeScope )
1160+ return false ;
1161+ const Function* destructor = vt->typeScope ->getDestructor ();
1162+ if (!destructor || !destructor->functionScope )
1163+ return false ;
1164+ const Scope* body = destructor->functionScope ;
1165+ for (const Token* tok = body->bodyStart ; tok != body->bodyEnd ; tok = tok->next ()) {
1166+ const Variable* var = tok->variable ();
1167+ if (!var || var->scope () != vt->typeScope || var->isStatic () || var->hasDefault ())
1168+ continue ;
1169+ if (!var->isPointer () && !var->typeStartToken ()->isStandardType () && !var->typeStartToken ()->isEnumType ())
1170+ continue ;
1171+ if (CheckUninitVarImpl::isVariableUsage (tok, library, var->isPointer (), CheckUninitVarImpl::NO_ALLOC ))
1172+ return true ;
1173+ }
1174+ return false ;
1175+ }
1176+
11561177const Token* CheckUninitVarImpl::isVariableUsage (const Token *vartok, const Library& library, bool pointer, Alloc alloc, int indirect)
11571178{
11581179 const bool cpp = vartok->isCpp ();
@@ -1253,8 +1274,8 @@ const Token* CheckUninitVarImpl::isVariableUsage(const Token *vartok, const Libr
12531274 return nullptr ;
12541275 if (Token::simpleMatch (valueExpr->astParent (), " return" ))
12551276 return nullptr ;
1256- // deallocating the memory does not read the data
1257- if (!derefValue && Token::simpleMatch (valueExpr->astParent (), " delete" ))
1277+ // deallocating the memory does not read the data, but the destructor might do that
1278+ if (Token::simpleMatch (valueExpr->astParent (), " delete" ) && ! isDataReadInDestructor (valueExpr-> valueType (), library ))
12581279 return nullptr ;
12591280 }
12601281
0 commit comments