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