diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 33112f766..331380c12 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -238,21 +238,29 @@ void CheckOther::clarifyStatement() return; for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { - if (Token::Match(tok, "[{};] * %var%")) { - tok = tok->tokAt(3); - while (tok) { - if (tok->str() == "[") - tok = tok->link()->next(); - if (Token::Match(tok, ".|:: %var%")) { - if (tok->strAt(2) == "(") - tok = tok->linkAt(2)->next(); - else - tok = tok->tokAt(2); - } else - break; + if (Token::Match(tok, "* %var%")) { + const Token *tok2=tok->previous(); + + while (Token::Match(tok2, "*")) + tok2=tok2->previous(); + + if (Token::Match(tok2, "[{};]")) { + tok = tok->tokAt(2); + while (tok) { + if (tok->str() == "[") + tok = tok->link()->next(); + + if (Token::Match(tok, ".|:: %var%")) { + if (tok->strAt(2) == "(") + tok = tok->linkAt(2)->next(); + else + tok = tok->tokAt(2); + } else + break; + } + if (Token::Match(tok, "++|-- [;,]")) + clarifyStatementError(tok); } - if (Token::Match(tok, "++|-- [;,]")) - clarifyStatementError(tok); } } } diff --git a/test/testother.cpp b/test/testother.cpp index 4d03c8f06..efe309058 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4040,6 +4040,29 @@ private: " bar(*c++);\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("char*** f(char*** c) {\n" + " ***c++;\n" + " return c;\n" + "}"); + ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective statement similar to '*A++;'. Did you intend to write '(*A)++;'?\n", errout.str()); + + check("char** f(char*** c) {\n" + " **c[5]--;\n" + " return **c;\n" + "}"); + ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective statement similar to '*A++;'. Did you intend to write '(*A)++;'?\n", errout.str()); + + check("char*** f(char*** c) {\n" + " (***c)++;\n" + " return c;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + check("void *f(char** c) {\n" + " bar(**c++);\n" + "}"); + ASSERT_EQUALS("", errout.str()); } // clarify conditions with = and comparison