@@ -1098,7 +1098,7 @@ void TokenList::createAst()
10981098
10991099void TokenList::validateAst ()
11001100{
1101- std::set < const Token* > astTokens ;
1101+ std::set < const Token* > safeAstTokens ;
11021102 // Verify that ast looks ok
11031103 for (const Token *tok = _front; tok; tok = tok->next ()) {
11041104 // Syntax error if binary operator only has 1 operand
@@ -1111,14 +1111,15 @@ void TokenList::validateAst()
11111111
11121112 // check for endless recursion
11131113 const Token* parent=tok;
1114+ std::set < const Token* > astTokens;
11141115 while ((parent = parent->astParent ()) != nullptr ) {
1115- if (parent==tok)
1116- throw InternalError (tok, " AST broken: endless recursion from '" + tok->str () + " '" , InternalError::SYNTAX);
1117- if (astTokens.find (parent)!= astTokens.end ()) {
1116+ if (safeAstTokens.find (parent)!= safeAstTokens.end ())
11181117 break ;
1119- }
1118+ if (astTokens.find (parent)!= astTokens.end ())
1119+ throw InternalError (tok, " AST broken: endless recursion from '" + tok->str () + " '" , InternalError::SYNTAX);
11201120 astTokens.insert (parent);
11211121 }
1122+ safeAstTokens.insert (astTokens.begin (), astTokens.end ());
11221123 }
11231124}
11241125
@@ -1136,7 +1137,7 @@ bool TokenList::validateToken(const Token* tok) const
11361137{
11371138 if (!tok)
11381139 return true ;
1139- for (Token *t = _front; t; t = t->next ()) {
1140+ for (const Token *t = _front; t; t = t->next ()) {
11401141 if (tok==t)
11411142 return true ;
11421143 }
0 commit comments