Fixed a bug in Tokenizer::concatenateNegativeNumber.

The first negative number inside a '{}' list was not simplified correctly.
This commit is contained in:
Edoardo Prezioso 2012-11-20 19:12:22 +01:00
parent ffe657128f
commit 5fb2115e9d
2 changed files with 2 additions and 1 deletions

View File

@ -2148,7 +2148,7 @@ void Tokenizer::simplifyNull()
void Tokenizer::concatenateNegativeNumber()
{
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "?|:|,|(|[|=|return|case|sizeof|%op% - %num%")) {
if (Token::Match(tok, "?|:|,|(|[|{|=|return|case|sizeof|%op% - %num%")) {
tok->deleteNext();
tok->next()->str("-" + tok->next()->str());
}

View File

@ -815,6 +815,7 @@ private:
ASSERT_EQUALS("1 - 2", tokenizeAndStringify("1-2"));
ASSERT_EQUALS("foo ( -1 ) - 2", tokenizeAndStringify("foo(-1)-2"));
ASSERT_EQUALS("int f ( ) { return -2 ; }", tokenizeAndStringify("int f(){return -2;}"));
ASSERT_EQUALS("int x [ 2 ] = { -2 , 1 }", tokenizeAndStringify("int x[2] = {-2,1}"));
}