diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 0ef1aa445..550851152 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -772,6 +772,9 @@ void CheckOther::checkRedundantAssignment() } } else if (Token::Match(tok, "%var% (")) { // Function call. Global variables might be used. Reset their status const bool memfunc = Token::Match(tok, "memcpy|memmove|memset|strcpy|strncpy|sprintf|snprintf|strcat|strncat|wcscpy|wcsncpy|swprintf|wcscat|wcsncat"); + if (tok->varId()) // operator() or function pointer + varAssignments.erase(tok->varId()); + if (memfunc) { const Token* param1 = tok->tokAt(2); writtenArgumentsEnd = param1->next(); diff --git a/test/testother.cpp b/test/testother.cpp index f5699c0e5..c3368beae 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6249,6 +6249,13 @@ private: "}", nullptr, false, false, false, false); ASSERT_EQUALS("", errout.str()); + check("void f() {\n" + " Foo bar = foo();\n" + " bar();\n" // #5568. operator() called + " bar = y();\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // Branch tests check("void f(int i) {\n" " i = 1;\n"