Fixed #5332 (Tokenizer: if braces not added properly 'if (x==123) label: {}')
This commit is contained in:
parent
3d0338e9f9
commit
26612ab846
|
@ -4521,6 +4521,11 @@ Token *Tokenizer::simplifyAddBracesPair(Token *tok, bool commandWithCondition)
|
|||
|
||||
Token::createMutualLinks(tokOpenBrace, tokCloseBrace);
|
||||
tokBracesEnd = tokCloseBrace;
|
||||
} else if (Token::Match(tokAfterCondition, "%name% : {")) {
|
||||
tokAfterCondition->previous()->insertToken("{");
|
||||
tokAfterCondition->linkAt(2)->insertToken("}");
|
||||
tokBracesEnd = tokAfterCondition->linkAt(2)->next();
|
||||
Token::createMutualLinks(tokAfterCondition->previous(), tokBracesEnd);
|
||||
} else {
|
||||
Token * tokEnd = simplifyAddBracesToCommand(tokAfterCondition);
|
||||
if (!tokEnd) // Ticket #4887
|
||||
|
|
|
@ -117,6 +117,7 @@ private:
|
|||
TEST_CASE(ifAddBraces18); // #3424 - if if { } else else
|
||||
TEST_CASE(ifAddBraces19); // #3928 - if for if else
|
||||
TEST_CASE(ifAddBraces20); // #5012 - syntax error 'else }'
|
||||
TEST_CASE(ifAddBraces21); // #5332 - if (x) label: {} ..
|
||||
|
||||
TEST_CASE(whileAddBraces);
|
||||
TEST_CASE(doWhileAddBraces);
|
||||
|
@ -1247,6 +1248,11 @@ private:
|
|||
ASSERT_THROW(tokenizeAndStringify(code, true), InternalError);
|
||||
}
|
||||
|
||||
void ifAddBraces21() { // #5332 - if (x) label: {} ...
|
||||
const char code[] = "void f() { if(x) label: {} a=1; }";
|
||||
ASSERT_EQUALS("void f ( ) { if ( x ) { label : ; { } } a = 1 ; }", tokenizeAndStringify(code, false));
|
||||
}
|
||||
|
||||
void whileAddBraces() {
|
||||
const char code[] = ";while(a);";
|
||||
ASSERT_EQUALS("; while ( a ) { ; }", tokenizeAndStringify(code, true));
|
||||
|
|
Loading…
Reference in New Issue