Refactoring CheckMemoryLeakNoVar::checkForUnusedReturnValue(). use continue
This commit is contained in:
parent
7663b6ee75
commit
0fb9ab7b4a
|
@ -2634,13 +2634,27 @@ void CheckMemoryLeakNoVar::check()
|
|||
void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope)
|
||||
{
|
||||
for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
|
||||
if (!tok->varId() && Token::Match(tok, "%name% (") && (!tok->function() || !Token::Match(tok->function()->retDef, "void %name%"))
|
||||
&& (!tok->next()->astParent() || tok->next()->astParent()->str() == "!" || tok->next()->astParent()->isComparisonOp()) && tok->next()->astOperand1() == tok) {
|
||||
if (!Token::Match(tok, "%name% ("))
|
||||
continue;
|
||||
|
||||
if (tok->varId())
|
||||
continue;
|
||||
|
||||
const AllocType allocType = getAllocationType(tok, 0);
|
||||
if (allocType != No)
|
||||
if (allocType == No)
|
||||
continue;
|
||||
|
||||
if (tok != tok->next()->astOperand1())
|
||||
continue;
|
||||
|
||||
// get ast parent, skip casts
|
||||
const Token *parent = tok->next()->astParent();
|
||||
while (parent && parent->str() == "(" && !parent->astOperand2())
|
||||
parent = parent->astParent();
|
||||
|
||||
if (!parent || Token::Match(parent, "%comp%|!"))
|
||||
returnValueNotUsedError(tok, tok->str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -5714,6 +5714,11 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo() {\n" // #7348 - cast
|
||||
" p = (::X*)malloc(42);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #7182 "crash: CheckMemoryLeak::functionReturnType()"
|
||||
check("template<typename... Ts> auto unary_right_comma (Ts... ts) { return (ts , ...); }\n"
|
||||
"template<typename T, typename... Ts> auto binary_left_comma (T x, Ts... ts) { return (x , ... , ts); }\n"
|
||||
|
|
Loading…
Reference in New Issue