Fixed #8628 (Wrong AST in case)

This commit is contained in:
Daniel Marjamäki 2018-11-10 21:32:06 +01:00
parent d5a478d5c5
commit 8327aab127
2 changed files with 11 additions and 3 deletions

View File

@ -362,7 +362,7 @@ struct AST_state {
unsigned int inArrayAssignment;
bool cpp;
unsigned int assign;
bool inCase;
bool inCase; // true from case to :
explicit AST_state(bool cpp_) : depth(0), inArrayAssignment(0), cpp(cpp_), assign(0U), inCase(false) {}
};
@ -563,8 +563,10 @@ static void compileTerm(Token *&tok, AST_state& state)
state.inCase = true;
compileUnaryOp(tok, state, compileExpression);
state.op.pop();
if (state.inCase && Token::simpleMatch(tok, ": ;"))
if (state.inCase && Token::simpleMatch(tok, ": ;")) {
state.inCase = false;
tok = tok->next();
}
} else if (Token::Match(tok, "sizeof !!(")) {
compileUnaryOp(tok, state, compileExpression);
state.op.pop();
@ -967,8 +969,11 @@ static void compileAssignTernary(Token *&tok, AST_state& state)
compileBinOp(tok, state, compileAssignTernary);
state.assign = assign;
} else if (tok->str() == ":") {
if (state.depth == 1U && state.inCase)
if (state.depth == 1U && state.inCase) {
state.inCase = false;
tok = tok->next();
break;
}
if (state.assign > 0U)
break;
compileBinOp(tok, state, compileAssignTernary);

View File

@ -8561,6 +8561,9 @@ private:
ASSERT_EQUALS("x{([= 0return", testAst("x = [](){return 0; };"));
ASSERT_EQUALS("ab{[(= cd=", testAst("a = b([&]{c=d;});"));
// 8628
ASSERT_EQUALS("f{([( switchx( 1case y++", testAst("f([](){switch(x){case 1:{++y;}}});"));
}
void astcase() {