Fixed #3424 (Tokenizer: doesn't tokenize if-if-else-else correctly)
This commit is contained in:
parent
f306246c7f
commit
d21ca7881c
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue