Fixed false positive redundantAssignment when operator() is called (#5568)

This commit is contained in:
PKEuS 2014-04-10 21:56:30 +02:00
parent 559a2bc2c8
commit c33498fa0b
2 changed files with 10 additions and 0 deletions

View File

@ -772,6 +772,9 @@ void CheckOther::checkRedundantAssignment()
} }
} else if (Token::Match(tok, "%var% (")) { // Function call. Global variables might be used. Reset their status } 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"); 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) { if (memfunc) {
const Token* param1 = tok->tokAt(2); const Token* param1 = tok->tokAt(2);
writtenArgumentsEnd = param1->next(); writtenArgumentsEnd = param1->next();

View File

@ -6249,6 +6249,13 @@ private:
"}", nullptr, false, false, false, false); "}", nullptr, false, false, false, false);
ASSERT_EQUALS("", errout.str()); 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 // Branch tests
check("void f(int i) {\n" check("void f(int i) {\n"
" i = 1;\n" " i = 1;\n"