diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 0d360a76e..031fa0525 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -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) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 51311afd5..d90cf14df 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -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"