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() {