Ticket #6536: Properly handle variables whose name is that of an allocation function.

This commit is contained in:
Simon Martin 2015-06-19 23:44:43 +02:00
parent af4a4663e2
commit cba0583045
2 changed files with 9 additions and 1 deletions

View File

@ -2745,7 +2745,7 @@ void CheckMemoryLeakNoVar::check()
void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope)
{
for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
if (Token::Match(tok, "%name% (") && (!tok->next()->astParent() || tok->next()->astParent()->str() == "!" || tok->next()->astParent()->isComparisonOp()) && tok->next()->astOperand1() == tok) {
if (!tok->varId() && Token::Match(tok, "%name% (") && (!tok->next()->astParent() || tok->next()->astParent()->str() == "!" || tok->next()->astParent()->isComparisonOp()) && tok->next()->astOperand1() == tok) {
const AllocType allocType = getAllocationType(tok, 0);
if (allocType != No)
returnValueNotUsedError(tok, tok->str());

View File

@ -6194,6 +6194,7 @@ private:
void run() {
settings.inconclusive = true;
settings.standards.posix = true;
settings.addEnabled("warning");
LOAD_LIB_2(settings.library, "gtk.cfg");
@ -6374,6 +6375,13 @@ private:
" return foo;\n"
"}");
ASSERT_EQUALS("", errout.str());
// Ticket #6536
check("struct S { S(int) {} };\n"
"void foo(int i) {\n"
" S socket(i);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void smartPointerFunctionParam() {