AST; Fix wrong AST for initializer list

This commit is contained in:
Daniel Marjamäki 2021-05-04 19:02:29 +02:00
parent 08184f4681
commit 2f984b201a
3 changed files with 9 additions and 6 deletions

View File

@ -943,7 +943,8 @@ static bool isForLoopCondition(const Token * const tok)
parent->astParent()->astParent()->astOperand1()->str() == "for"; parent->astParent()->astParent()->astOperand1()->str() == "for";
} }
static bool isZeroConstant(const Token *tok) { static bool isZeroConstant(const Token *tok)
{
while (tok && tok->isCast()) while (tok && tok->isCast())
tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1(); tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
return Token::simpleMatch(tok, "0") && !tok->isExpandedMacro(); return Token::simpleMatch(tok, "0") && !tok->isExpandedMacro();

View File

@ -844,8 +844,9 @@ static void compileTerm(Token *&tok, AST_state& state)
} else if (state.cpp && iscpp11init(tok)) { } else if (state.cpp && iscpp11init(tok)) {
if (state.op.empty() || Token::Match(tok->previous(), "[{,]") || Token::Match(tok->tokAt(-2), "%name% (")) { if (state.op.empty() || Token::Match(tok->previous(), "[{,]") || Token::Match(tok->tokAt(-2), "%name% (")) {
if (Token::Match(tok, "{ !!}")) { if (Token::Match(tok, "{ !!}")) {
Token *end = tok->link(); Token *const end = tok->link();
compileUnaryOp(tok, state, compileExpression); compileUnaryOp(tok, state, compileExpression);
if (precedes(tok,end))
tok = end; tok = end;
} else { } else {
state.op.push(tok); state.op.push(tok);

View File

@ -5815,6 +5815,7 @@ private:
ASSERT_EQUALS("f1{2{,3{,{x,(", testAst("f({{1},{2},{3}},x);")); ASSERT_EQUALS("f1{2{,3{,{x,(", testAst("f({{1},{2},{3}},x);"));
ASSERT_EQUALS("a1{ b2{", testAst("auto a{1}; auto b{2};")); ASSERT_EQUALS("a1{ b2{", testAst("auto a{1}; auto b{2};"));
ASSERT_EQUALS("var1ab::23,{,{4ab::56,{,{,{", testAst("auto var{{1,a::b{2,3}}, {4,a::b{5,6}}};")); ASSERT_EQUALS("var1ab::23,{,{4ab::56,{,{,{", testAst("auto var{{1,a::b{2,3}}, {4,a::b{5,6}}};"));
ASSERT_EQUALS("var{{,{,{{", testAst("auto var{ {{},{}}, {} };"));
// Initialization with decltype(expr) instead of a type // Initialization with decltype(expr) instead of a type
ASSERT_EQUALS("decltypex((", testAst("decltype(x)();")); ASSERT_EQUALS("decltypex((", testAst("decltype(x)();"));