diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 6c68ff6f3..0a1ba0610 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -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) && diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 552a7e3f2..cc2e082d6 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -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" "}");