Fixed #8786 (internalAstError on valid code with C style cast)
This commit is contained in:
parent
4983a6a5dc
commit
465db2dff7
@ -753,7 +753,14 @@ static void compilePrecedence3(Token *&tok, AST_state& state)
|
|||||||
} else if (tok->str() == "(" && iscast(tok)) {
|
} else if (tok->str() == "(" && iscast(tok)) {
|
||||||
Token* tok2 = tok;
|
Token* tok2 = tok;
|
||||||
tok = tok->link()->next();
|
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);
|
compileUnaryOp(tok2, state, nullptr);
|
||||||
} else if (state.cpp && Token::Match(tok, "new %name%|::|(")) {
|
} else if (state.cpp && Token::Match(tok, "new %name%|::|(")) {
|
||||||
Token* newtok = tok;
|
Token* newtok = tok;
|
||||||
@ -1232,9 +1239,6 @@ void TokenList::validateAst() const
|
|||||||
// FIXME: Workaround when assigning from a new expression: #8749
|
// FIXME: Workaround when assigning from a new expression: #8749
|
||||||
if (Token::simpleMatch(tok, "= new"))
|
if (Token::simpleMatch(tok, "= new"))
|
||||||
continue;
|
continue;
|
||||||
// FIXME: Workaround assigning when using c style cast: #8786
|
|
||||||
if (Token::Match(tok, "= ( %name%"))
|
|
||||||
continue;
|
|
||||||
if (!tok->astOperand1() || !tok->astOperand2())
|
if (!tok->astOperand1() || !tok->astOperand2())
|
||||||
throw InternalError(tok, "Syntax Error: AST broken, binary operator '" + tok->str() + "' doesn't have two operands.", InternalError::AST);
|
throw InternalError(tok, "Syntax Error: AST broken, binary operator '" + tok->str() + "' doesn't have two operands.", InternalError::AST);
|
||||||
}
|
}
|
||||||
|
@ -1624,12 +1624,6 @@ private:
|
|||||||
" char (*p)[1] = new A[1];\n"
|
" char (*p)[1] = new A[1];\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
// #8786
|
|
||||||
checkCode(
|
|
||||||
"void f() {\n"
|
|
||||||
" char * pBuf = (char*)(new int[32]);\n"
|
|
||||||
"}\n");
|
|
||||||
|
|
||||||
// #8749
|
// #8749
|
||||||
checkCode(
|
checkCode(
|
||||||
"struct A {\n"
|
"struct A {\n"
|
||||||
|
@ -8403,6 +8403,8 @@ private:
|
|||||||
ASSERT_EQUALS("a1(2+=",testAst("a=(t&)1+2;"));
|
ASSERT_EQUALS("a1(2+=",testAst("a=(t&)1+2;"));
|
||||||
ASSERT_EQUALS("ab::r&c(=", testAst("a::b& r = (a::b&)c;")); // #5261
|
ASSERT_EQUALS("ab::r&c(=", testAst("a::b& r = (a::b&)c;")); // #5261
|
||||||
ASSERT_EQUALS("ab10:?=", testAst("a=(b)?1:0;"));
|
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)
|
// 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;"));
|
ASSERT_EQUALS("a&(", testAst("(int (**)[i]){&a}[0][1][5] = 0;"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user