Fixed #8691 (False negative for uselessAssignmentArg)

This commit is contained in:
Daniel Marjamäki 2018-08-17 19:56:36 +02:00
parent e442bc47b1
commit 43233e72b2
2 changed files with 6 additions and 1 deletions

View File

@ -190,7 +190,7 @@ void CheckAutoVariables::assignFunctionArg()
// TODO: What happens if this is removed?
if (tok->astParent())
continue;
if (!Token::Match(tok, "=|++|--") || !Token::Match(tok->astOperand1(), "%var%"))
if (!(tok->isAssignmentOp() || Token::Match(tok, "++|--")) || !Token::Match(tok->astOperand1(), "%var%"))
continue;
const Token* const vartok = tok->astOperand1();
if (isNonReferenceArg(vartok) &&

View File

@ -274,6 +274,11 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Assignment of function parameter has no effect outside the function.\n", errout.str());
check("void foo(int b) {\n"
" b += 1;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Assignment of function parameter has no effect outside the function.\n", errout.str());
check("void foo(std::string s) {\n"
" s = foo(b);\n"
"}");