diff --git a/cfg/std.cfg b/cfg/std.cfg index 724630703..d2f31340e 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -4103,6 +4103,9 @@ false + + + diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 8cf741982..074a435a9 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1495,6 +1495,11 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok, *alloc = true; continue; } + if (var.isPointer() && (_tokenizer->isC() || var.typeStartToken()->isStandardType() || (var.type() && var.type()->needInitialization == Type::True)) && Token::Match(tok->next(), "= new")) { + if (alloc) + *alloc = true; + continue; + } if (!membervar.empty()) { @@ -1676,7 +1681,7 @@ void CheckUninitVar::checkRhs(const Token *tok, const Variable &var, bool alloc, bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool alloc) const { - if (!alloc && vartok->previous()->str() == "return" && vartok->strAt(1) != "=") + if (!alloc && ((Token::Match(vartok->previous(), "return|delete") && vartok->strAt(1) != "=") || (vartok->strAt(-1) == "]" && vartok->linkAt(-1)->strAt(-1) == "delete"))) return true; // Passing variable to typeof/__alignof__