Fixed #8786 (internalAstError on valid code with C style cast)

This commit is contained in:
Daniel Marjamäki 2018-10-18 20:17:23 +02:00
parent 4983a6a5dc
commit 465db2dff7
3 changed files with 10 additions and 10 deletions

View File

@ -753,7 +753,14 @@ static void compilePrecedence3(Token *&tok, AST_state& state)
} else if (tok->str() == "(" && iscast(tok)) {
Token* tok2 = tok;
tok = tok->link()->next();
compilePrecedence3(tok, state);
if (tok && tok->str() == "(" && !iscast(tok)) {
Token *tok3 = tok->next();
compileExpression(tok3, state);
if (tok->link() == tok3)
tok = tok3->next();
} else {
compilePrecedence3(tok, state);
}
compileUnaryOp(tok2, state, nullptr);
} else if (state.cpp && Token::Match(tok, "new %name%|::|(")) {
Token* newtok = tok;
@ -1232,9 +1239,6 @@ void TokenList::validateAst() const
// FIXME: Workaround when assigning from a new expression: #8749
if (Token::simpleMatch(tok, "= new"))
continue;
// FIXME: Workaround assigning when using c style cast: #8786
if (Token::Match(tok, "= ( %name%"))
continue;
if (!tok->astOperand1() || !tok->astOperand2())
throw InternalError(tok, "Syntax Error: AST broken, binary operator '" + tok->str() + "' doesn't have two operands.", InternalError::AST);
}

View File

@ -1624,12 +1624,6 @@ private:
" char (*p)[1] = new A[1];\n"
"}\n");
// #8786
checkCode(
"void f() {\n"
" char * pBuf = (char*)(new int[32]);\n"
"}\n");
// #8749
checkCode(
"struct A {\n"

View File

@ -8403,6 +8403,8 @@ private:
ASSERT_EQUALS("a1(2+=",testAst("a=(t&)1+2;"));
ASSERT_EQUALS("ab::r&c(=", testAst("a::b& r = (a::b&)c;")); // #5261
ASSERT_EQUALS("ab10:?=", testAst("a=(b)?1:0;"));
ASSERT_EQUALS("ac5[new(=", testAst("a = (b*)(new c[5]);")); // #8786
ASSERT_EQUALS("a(4+", testAst("(int)(a) + 4;"));
// TODO: This AST is incomplete however it's very weird syntax (taken from clang test suite)
ASSERT_EQUALS("a&(", testAst("(int (**)[i]){&a}[0][1][5] = 0;"));