Fixed #5064 (Tokenizer::simplifySizeof: Doesn't simplify 'sizeof !! (a==1);' properly)

This commit is contained in:
Daniel Marjamäki 2013-10-06 08:20:10 +02:00
parent 9cfc1030cd
commit c234cace6d
2 changed files with 13 additions and 2 deletions

View File

@ -3320,9 +3320,17 @@ bool Tokenizer::simplifySizeof()
for (Token *tempToken = tok->next(); tempToken; tempToken = tempToken->next()) {
if (tempToken->str() == "(")
++parlevel;
else if (tempToken->str() == ")")
else if (tempToken->str() == ")") {
--parlevel;
if (Token::Match(tempToken, "%var%")) {
if (parlevel == 0 && !Token::Match(tempToken, ") . %var%")) {
// Ok, we should be clean. Add ) after tempToken
tok->insertToken("(");
tempToken->insertToken(")");
Token::createMutualLinks(tok->next(), tempToken->next());
break;
}
}
if (parlevel == 0 && Token::Match(tempToken, "%var%")) {
while (tempToken && tempToken->next() && tempToken->next()->str() == "[") {
tempToken = tempToken->next()->link();
}

View File

@ -1325,6 +1325,9 @@ private:
" int aa ; aa = sizeof ( * ( * a ) . b ) ; "
"}";
ASSERT_EQUALS(expected, tok(code));
// #5064 - sizeof !! (a == 1);
ASSERT_EQUALS("sizeof ( ! ! ( a == 1 ) ) ;", tok("sizeof !!(a==1);"));
}
void sizeof15() {