Fix issue 9443: Internal error: Token::astOperand2() cyclic dependency. (#2376)
* Improve nested init lists * Fix issue 9443: Internal error: Token::astOperand2() cyclic dependency.
This commit is contained in:
parent
55051b777b
commit
479fbb85a2
|
@ -551,6 +551,8 @@ static bool iscpp11init(const Token * const tok)
|
|||
|
||||
static bool iscpp11init_impl(const Token * const tok)
|
||||
{
|
||||
if (Token::simpleMatch(tok, "{") && Token::simpleMatch(tok->link()->previous(), "; }"))
|
||||
return false;
|
||||
const Token *nameToken = tok;
|
||||
while (nameToken && nameToken->str() == "{") {
|
||||
if (nameToken->isCpp11init() != TokenImpl::Cpp11init::UNKNOWN)
|
||||
|
@ -569,6 +571,8 @@ static bool iscpp11init_impl(const Token * const tok)
|
|||
endtok = nameToken->linkAt(1);
|
||||
else if (Token::Match(nameToken,"%name% <") && Token::simpleMatch(nameToken->linkAt(1),"> {"))
|
||||
endtok = nameToken->linkAt(1)->linkAt(1);
|
||||
else if (Token::Match(nameToken->previous(), "%name% ( {"))
|
||||
endtok = nameToken->linkAt(1);
|
||||
else
|
||||
return false;
|
||||
if (Token::Match(nameToken, "else|try|do|const|override|volatile|&|&&"))
|
||||
|
@ -704,7 +708,7 @@ static void compileTerm(Token *&tok, AST_state& state)
|
|||
if (Token::simpleMatch(tok->link(),"} [")) {
|
||||
tok = tok->next();
|
||||
} else if (state.cpp && iscpp11init(tok)) {
|
||||
if (state.op.empty() || Token::Match(tok->previous(), "[{,]"))
|
||||
if (state.op.empty() || Token::Match(tok->previous(), "[{,]") || Token::Match(tok->tokAt(-2), "%name% ("))
|
||||
compileUnaryOp(tok, state, compileExpression);
|
||||
else
|
||||
compileBinOp(tok, state, compileExpression);
|
||||
|
|
|
@ -7603,12 +7603,14 @@ private:
|
|||
ASSERT_EQUALS("xabc({((= ydef({((=",
|
||||
testAst("x=(int)(a({b(c);}));" // don't hang
|
||||
"y=(int)(d({e(f);}));"));
|
||||
ASSERT_EQUALS("A{,( x0= Bx1={{,( x2=", // TODO: This is not perfect!!
|
||||
ASSERT_EQUALS("A{{,( x0= Bx1={x2={,(", // TODO: This is not perfect!!
|
||||
testAst("A({},{x=0;});" // don't hang
|
||||
"B({x=1},{x=2});"));
|
||||
ASSERT_EQUALS("xMACROtype.T=value.1=,{({=",
|
||||
testAst("x = { MACRO( { .type=T, .value=1 } ) }")); // don't hang: MACRO({..})
|
||||
ASSERT_EQUALS("fori10=i{;;( i--", testAst("for (i=10;i;({i--;}) ) {}"));
|
||||
ASSERT_EQUALS("c{0{,{(",
|
||||
testAst("c({{}, {0}}, {0.0f});"));
|
||||
|
||||
// function pointer
|
||||
TODO_ASSERT_EQUALS("todo", "va_argapvoid((,(*0=", testAst("*va_arg(ap, void(**) ()) = 0;"));
|
||||
|
@ -7703,7 +7705,7 @@ private:
|
|||
ASSERT_EQUALS("xsizeofvoid(=", testAst("x=sizeof(void*)"));
|
||||
ASSERT_EQUALS("abc{d{,{(=", testAst("a = b({ c{}, d{} });"));
|
||||
ASSERT_EQUALS("abc;(", testAst("a(b;c)"));
|
||||
ASSERT_THROW(testAst("a({ for(a;b;c){} });"), InternalError);
|
||||
ASSERT_EQUALS("aforab;c;({(", testAst("a({ for(a;b;c){} });"));
|
||||
}
|
||||
|
||||
void asttemplate() { // uninstantiated templates will have <,>,etc..
|
||||
|
@ -7775,7 +7777,7 @@ private:
|
|||
" a = b;\n"
|
||||
" }\n"
|
||||
"};\n"));
|
||||
ASSERT_EQUALS("{return ab={",
|
||||
ASSERT_EQUALS("{return ab=",
|
||||
testAst("return {\n"
|
||||
" [=]() -> int {\n"
|
||||
" a=b;\n"
|
||||
|
|
Loading…
Reference in New Issue