assignFunctionArg: don't warn when there is self assignment. There is a separate warning for self assignments.

This commit is contained in:
Daniel Marjamäki 2015-08-09 14:51:23 +02:00
parent 4e4a1cfe3a
commit 9627fccdc5
2 changed files with 6 additions and 0 deletions

View File

@ -130,6 +130,7 @@ void CheckAutoVariables::assignFunctionArg()
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
if (Token::Match(tok, "[;{}] %var% =|++|--") &&
isNonReferenceArg(tok->next()) &&
!Token::Match(tok->tokAt(2), "= %varid% ;", tok->next()->varId()) &&
!variableIsUsedInScope(Token::findsimplematch(tok->tokAt(2), ";"), tok->next()->varId(), scope) &&
!Token::findsimplematch(tok, "goto", scope->classEnd)) {
if (tok->next()->variable()->isPointer() && printWarning)

View File

@ -263,6 +263,11 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Assignment of function parameter has no effect outside the function.\n", errout.str());
check("void foo(char* p) {\n" // don't warn for self assignment, there is another warning for this
" p = p;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo(char* p) {\n"
" if (!p) p = buf;\n"
" *p = 0;\n"