Fixed #2321 (false positive: (performance) Prefer prefix ++/-- operators for non-primitive types.)

This commit is contained in:
Daniel Marjamäki 2010-12-30 14:27:05 +01:00
parent 20887a40a3
commit 7ec169f66a
2 changed files with 12 additions and 0 deletions

View File

@ -74,6 +74,9 @@ void CheckPostfixOperator::postfixOperator()
if (result && tok->previous()->varId()) if (result && tok->previous()->varId())
{ {
const Token *decltok = Token::findmatch(_tokenizer->tokens(), "%varid%", 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")) if (decltok && Token::Match(decltok->previous(), "iterator|const_iterator|reverse_iterator|const_reverse_iterator"))
{ {
// the variable is an iterator // the variable is an iterator

View File

@ -69,6 +69,7 @@ private:
TEST_CASE(testvolatile); TEST_CASE(testvolatile);
TEST_CASE(testiterator); TEST_CASE(testiterator);
TEST_CASE(test2168); TEST_CASE(test2168);
TEST_CASE(pointer); // #2321 - postincrement of pointer is OK
} }
void testsimple() void testsimple()
@ -372,6 +373,14 @@ private:
"int main(){}\n"); "int main(){}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void pointer()
{
check("static struct class * ab;\n"
"int * p;\n"
"p++;\n");
ASSERT_EQUALS("", errout.str());
}
}; };
REGISTER_TEST(TestPostfixOperator) REGISTER_TEST(TestPostfixOperator)