AST: Fixed bad syntax tree for 'if (x()[0]==1);'

This commit is contained in:
Daniel Marjamäki 2014-04-05 08:03:24 +02:00
parent 173a2e9ea2
commit 049d68ae7d
3 changed files with 21 additions and 18 deletions

View File

@ -460,28 +460,30 @@ static void compileTerm(Token *& tok, std::stack<Token*> &op)
} else {
Token *name = tok;
Token *par = templatefunc ? tok->linkAt(1)->next() : tok->next();
Token *prev;
tok = par->next();
if (Token::Match(tok, ")|]")) {
prev = name;
par->astOperand1(name);
tok = tok->next();
} else {
Token *prev = name;
prev = name;
tok = tok->previous();
while (Token::Match(tok, "(|[")) {
Token *tok1 = tok;
}
while (Token::Match(tok, "(|[")) {
Token *tok1 = tok;
tok = tok->next();
while (Token::Match(tok,"%var% %var%")) // example: sizeof(struct S)
tok = tok->next();
while (Token::Match(tok,"%var% %var%")) // example: sizeof(struct S)
tok = tok->next();
compileExpression(tok, op);
if (!op.empty()) {
tok1->astOperand2(op.top());
op.pop();
}
tok1->astOperand1(prev);
prev = tok1;
if (Token::Match(tok, "]|)"))
tok = tok->next();
compileExpression(tok, op);
if (!op.empty()) {
tok1->astOperand2(op.top());
op.pop();
}
tok1->astOperand1(prev);
prev = tok1;
if (Token::Match(tok, "]|)"))
tok = tok->next();
}
op.push(par);
}

View File

@ -2906,10 +2906,10 @@ private:
// Ticket #5641 "Regression. Crash for 'C() _STLP_NOTHROW {}'"
void constructors_crash1() {
check("class C {\n"
"public:\n"
" C() _STLP_NOTHROW {}\n"
" C(const C&) _STLP_NOTHROW {}\n"
"};\n");
"public:\n"
" C() _STLP_NOTHROW {}\n"
" C(const C&) _STLP_NOTHROW {}\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
};

View File

@ -10324,6 +10324,7 @@ private:
ASSERT_EQUALS("QT_WA{{,( QT_WA{{,( x1=",
testAst("QT_WA({},{x=0;});" // don't hang
"QT_WA({x=1;},{x=2;});"));
ASSERT_EQUALS("ifa(0[1==(", testAst("if(a()[0]==1){}"));
}
void astbrackets() const { // []