Fixed #3424 (Tokenizer: doesn't tokenize if-if-else-else correctly)

This commit is contained in:
Daniel Marjamäki 2011-12-17 19:05:14 +01:00
parent f306246c7f
commit d21ca7881c
2 changed files with 10 additions and 1 deletions

View File

@ -4913,7 +4913,9 @@ bool Tokenizer::simplifyIfAddBraces()
tempToken = tempToken->link();
if (!tempToken || !tempToken->next())
break;
if (tempToken->next()->isName() && tempToken->next()->str() != "else")
if (Token::simpleMatch(tempToken, "} else") && !Token::Match(tempToken->tokAt(2), "if|{"))
innerIf = false;
else if (tempToken->next()->isName() && tempToken->next()->str() != "else")
break;
continue;
}

View File

@ -87,6 +87,7 @@ private:
TEST_CASE(ifAddBraces14); // #2610 - segfault: if()<{}
TEST_CASE(ifAddBraces15); // #2616 - unknown macro before if
TEST_CASE(ifAddBraces16); // '} else' should be in the same line
TEST_CASE(ifAddBraces17); // #3424 - if if { } else else
TEST_CASE(whileAddBraces);
TEST_CASE(doWhileAddBraces);
@ -963,6 +964,12 @@ private:
"}", tokenizeAndStringify(code, true));
}
void ifAddBraces17() {
// ticket #3424 - if if { } else else
ASSERT_EQUALS("{ if ( x ) { if ( y ) { } else { ; } } else { ; } }",
tokenizeAndStringify("{ if(x) if(y){}else;else;}", false));
}
void whileAddBraces() {