From 43233e72b2c1bd52e9b52383276aa5200a20cfce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 17 Aug 2018 19:56:36 +0200 Subject: [PATCH] Fixed #8691 (False negative for uselessAssignmentArg) --- lib/checkautovariables.cpp | 2 +- test/testautovariables.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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" "}");