Fixed #951 (Preincremented struct member confused with numeric constant)

This commit is contained in:
Daniel Marjamäki 2009-11-12 22:16:24 +01:00
parent d2db4d3a27
commit b2cec721c0
2 changed files with 18 additions and 2 deletions

View File

@ -3405,7 +3405,7 @@ bool Tokenizer::simplifyKnownVariables()
Token::Match(tok2, "%var% = %bool% ;") ||
Token::Match(tok2, "%var% = %var% ;")))
{
unsigned int varid = tok2->varId();
const unsigned int varid = tok2->varId();
if (varid == 0)
continue;
@ -3522,7 +3522,7 @@ bool Tokenizer::simplifyKnownVariables()
ret = true;
}
if (Token::Match(tok3->next(), "++|-- %varid%", varid))
if (Token::Match(tok3->next(), "++|-- %varid% !!.", varid))
{
incdec(value, tok3->strAt(1));
tok2->tokAt(2)->str(value);

View File

@ -2197,6 +2197,22 @@ private:
ASSERT_EQUALS(expected, tok(code));
}
{
const char code[] = "void foo(Result* ptr)\n"
"{\n"
" Result* obj = ptr;\n"
" ++obj->total;\n"
"}\n";
const char expected[] = "void foo ( Result * ptr ) "
"{ "
"Result * obj ; obj = ptr ; "
"++ obj . total ; "
"}";
ASSERT_EQUALS(expected, tok(code));
}
}