Fixed #5012 (Hang when there is syntax error 'else }')
This commit is contained in:
parent
2fe91e290c
commit
9000c233fa
|
@ -4103,9 +4103,7 @@ bool Tokenizer::simplifyAddBraces()
|
|||
Token *Tokenizer::simplifyAddBracesToCommand(Token *tok)
|
||||
{
|
||||
Token * tokEnd=tok;
|
||||
if (tok->str()=="for" ||
|
||||
tok->str()=="BOOST_FOREACH" ||
|
||||
tok->str()=="switch") {
|
||||
if (Token::Match(tok,"for|switch|BOOST_FOREACH")) {
|
||||
tokEnd=simplifyAddBracesPair(tok,true);
|
||||
} else if (tok->str()=="while") {
|
||||
Token *tokPossibleDo=tok->previous();
|
||||
|
@ -4142,6 +4140,9 @@ Token *Tokenizer::simplifyAddBracesToCommand(Token *tok)
|
|||
if (tokEndNextNext && tokEndNextNext->str()=="if") {
|
||||
// do not change "else if ..." to "else { if ... }"
|
||||
tokEnd=simplifyAddBracesToCommand(tokEndNextNext);
|
||||
} else if (Token::simpleMatch(tokEndNext, "else }")) {
|
||||
syntaxError(tokEndNext);
|
||||
return NULL;
|
||||
} else
|
||||
tokEnd=simplifyAddBracesPair(tokEndNext,false);
|
||||
}
|
||||
|
|
|
@ -116,6 +116,7 @@ private:
|
|||
TEST_CASE(ifAddBraces17); // '} else' should be in the same line
|
||||
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(whileAddBraces);
|
||||
TEST_CASE(doWhileAddBraces);
|
||||
|
@ -1345,6 +1346,11 @@ private:
|
|||
"}", tokenizeAndStringify(code, true));
|
||||
}
|
||||
|
||||
void ifAddBraces20() { // #5012 - syntax error 'else }'
|
||||
const char code[] = "void f() { if(x) {} else }";
|
||||
tokenizeAndStringify(code,true);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
}
|
||||
|
||||
void whileAddBraces() {
|
||||
const char code[] = ";while(a);";
|
||||
|
|
Loading…
Reference in New Issue