diff --git a/lib/checkpostfixoperator.cpp b/lib/checkpostfixoperator.cpp index 87a24c430..3503f33a7 100644 --- a/lib/checkpostfixoperator.cpp +++ b/lib/checkpostfixoperator.cpp @@ -74,6 +74,9 @@ void CheckPostfixOperator::postfixOperator() if (result && tok->previous()->varId()) { const Token *decltok = Token::findmatch(_tokenizer->tokens(), "%varid%", tok->previous()->varId()); + if (!Token::Match(decltok->tokAt(-1), "%type%")) + continue; + if (decltok && Token::Match(decltok->previous(), "iterator|const_iterator|reverse_iterator|const_reverse_iterator")) { // the variable is an iterator diff --git a/test/testpostfixoperator.cpp b/test/testpostfixoperator.cpp index 4a93aec50..52d707df7 100644 --- a/test/testpostfixoperator.cpp +++ b/test/testpostfixoperator.cpp @@ -69,6 +69,7 @@ private: TEST_CASE(testvolatile); TEST_CASE(testiterator); TEST_CASE(test2168); + TEST_CASE(pointer); // #2321 - postincrement of pointer is OK } void testsimple() @@ -372,6 +373,14 @@ private: "int main(){}\n"); ASSERT_EQUALS("", errout.str()); } + + void pointer() + { + check("static struct class * ab;\n" + "int * p;\n" + "p++;\n"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestPostfixOperator)