From 7ec169f66ab64ee904c9bce8d3f665d7a95f648d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 30 Dec 2010 14:27:05 +0100 Subject: [PATCH] Fixed #2321 (false positive: (performance) Prefer prefix ++/-- operators for non-primitive types.) --- lib/checkpostfixoperator.cpp | 3 +++ test/testpostfixoperator.cpp | 9 +++++++++ 2 files changed, 12 insertions(+) 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)