Fixed #7347 (AST: wrong ast when template variable is declared and initiailized in if 'if (A::B<C> abc = 123)')
This commit is contained in:
parent
40e14f401f
commit
c0056d2455
|
@ -438,6 +438,26 @@ struct AST_state {
|
||||||
explicit AST_state(bool cpp_) : depth(0), inArrayAssignment(0), cpp(cpp_), assign(0U) {}
|
explicit AST_state(bool cpp_) : depth(0), inArrayAssignment(0), cpp(cpp_), assign(0U) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static Token * skipDecl(Token *tok)
|
||||||
|
{
|
||||||
|
if (!Token::Match(tok->previous(), "( %name%"))
|
||||||
|
return tok;
|
||||||
|
|
||||||
|
Token *vartok = tok;
|
||||||
|
while (Token::Match(vartok, "%name%|*|&|::|<")) {
|
||||||
|
if (vartok->str() == "<") {
|
||||||
|
if (vartok->link())
|
||||||
|
vartok = vartok->link();
|
||||||
|
else
|
||||||
|
return tok;
|
||||||
|
} else if (Token::Match(vartok, "%name% [:=]")) {
|
||||||
|
return vartok;
|
||||||
|
}
|
||||||
|
vartok = vartok->next();
|
||||||
|
}
|
||||||
|
return tok;
|
||||||
|
}
|
||||||
|
|
||||||
static bool iscast(const Token *tok)
|
static bool iscast(const Token *tok)
|
||||||
{
|
{
|
||||||
if (!Token::Match(tok, "( ::| %name%"))
|
if (!Token::Match(tok, "( ::| %name%"))
|
||||||
|
@ -577,6 +597,7 @@ static void compileTerm(Token *&tok, AST_state& state)
|
||||||
if (tok->str() == "<")
|
if (tok->str() == "<")
|
||||||
tok = tok->link()->next();
|
tok = tok->link()->next();
|
||||||
} else if (!state.cpp || !Token::Match(tok, "new|delete %name%|*|&|::|(|[")) {
|
} else if (!state.cpp || !Token::Match(tok, "new|delete %name%|*|&|::|(|[")) {
|
||||||
|
tok = skipDecl(tok);
|
||||||
while (tok->next() && tok->next()->isName())
|
while (tok->next() && tok->next()->isName())
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
state.op.push(tok);
|
state.op.push(tok);
|
||||||
|
@ -960,7 +981,7 @@ static void compileExpression(Token *&tok, AST_state& state)
|
||||||
static Token * createAstAtToken(Token *tok, bool cpp)
|
static Token * createAstAtToken(Token *tok, bool cpp)
|
||||||
{
|
{
|
||||||
if (Token::simpleMatch(tok, "for (")) {
|
if (Token::simpleMatch(tok, "for (")) {
|
||||||
Token *tok2 = tok->tokAt(2);
|
Token *tok2 = skipDecl(tok->tokAt(2));
|
||||||
Token *init1 = nullptr;
|
Token *init1 = nullptr;
|
||||||
Token * const endPar = tok->next()->link();
|
Token * const endPar = tok->next()->link();
|
||||||
while (tok2 && tok2 != endPar && tok2->str() != ";") {
|
while (tok2 && tok2 != endPar && tok2->str() != ";") {
|
||||||
|
|
|
@ -8104,6 +8104,9 @@ private:
|
||||||
ASSERT_EQUALS("fori1=current0=,iNUM<=i++;;(", testAst("for(i = (1), current = 0; i <= (NUM); ++i)"));
|
ASSERT_EQUALS("fori1=current0=,iNUM<=i++;;(", testAst("for(i = (1), current = 0; i <= (NUM); ++i)"));
|
||||||
ASSERT_EQUALS("foreachxy,((", testAst("for(each(x,y)){}")); // it's not well-defined what this ast should be
|
ASSERT_EQUALS("foreachxy,((", testAst("for(each(x,y)){}")); // it's not well-defined what this ast should be
|
||||||
ASSERT_EQUALS("forab:(", testAst("for (int a : b);"));
|
ASSERT_EQUALS("forab:(", testAst("for (int a : b);"));
|
||||||
|
ASSERT_EQUALS("forab:(", testAst("for (int *a : b);"));
|
||||||
|
ASSERT_EQUALS("forcd:(", testAst("for (a<b> c : d);"));
|
||||||
|
ASSERT_EQUALS("forde:(", testAst("for (a::b<c> d : e);"));
|
||||||
ASSERT_EQUALS("forx*0=yz;;(", testAst("for(*x=0;y;z)"));
|
ASSERT_EQUALS("forx*0=yz;;(", testAst("for(*x=0;y;z)"));
|
||||||
|
|
||||||
// problems with multiple expressions
|
// problems with multiple expressions
|
||||||
|
|
Loading…
Reference in New Issue