Skip to content

Commit 7ec169f

Browse files
author
Daniel Marjamäki
committed
Fixed danmar#2321 (false positive: (performance) Prefer prefix ++/-- operators for non-primitive types.)
1 parent 20887a4 commit 7ec169f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/checkpostfixoperator.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ void CheckPostfixOperator::postfixOperator()
7474
if (result && tok->previous()->varId())
7575
{
7676
const Token *decltok = Token::findmatch(_tokenizer->tokens(), "%varid%", tok->previous()->varId());
77+
if (!Token::Match(decltok->tokAt(-1), "%type%"))
78+
continue;
79+
7780
if (decltok && Token::Match(decltok->previous(), "iterator|const_iterator|reverse_iterator|const_reverse_iterator"))
7881
{
7982
// the variable is an iterator

test/testpostfixoperator.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class TestPostfixOperator : public TestFixture
6969
TEST_CASE(testvolatile);
7070
TEST_CASE(testiterator);
7171
TEST_CASE(test2168);
72+
TEST_CASE(pointer); // #2321 - postincrement of pointer is OK
7273
}
7374

7475
void testsimple()
@@ -372,6 +373,14 @@ class TestPostfixOperator : public TestFixture
372373
"int main(){}\n");
373374
ASSERT_EQUALS("", errout.str());
374375
}
376+
377+
void pointer()
378+
{
379+
check("static struct class * ab;\n"
380+
"int * p;\n"
381+
"p++;\n");
382+
ASSERT_EQUALS("", errout.str());
383+
}
375384
};
376385

377386
REGISTER_TEST(TestPostfixOperator)

0 commit comments

Comments
 (0)