From cba058304522c674f0cbc5de7ab92aebb93544d4 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Fri, 19 Jun 2015 23:44:43 +0200 Subject: [PATCH] Ticket #6536: Properly handle variables whose name is that of an allocation function. --- lib/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 4acea2df7..a730eb69f 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -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()); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index ac30a35f0..2c10098d6 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -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() {