@@ -563,6 +563,20 @@ namespace {
563563 if (Token::simpleMatch (start, " typename" ))
564564 start = start->next ();
565565
566+ const auto checkForRecursion = [this ]() {
567+ if (Token::Match (mTypedefToken , " typedef %name% %name% ;" ))
568+ return ;
569+ for (const Token *tok = mTypedefToken ; tok != mEndToken ; tok = tok->next ()) {
570+ if (tok == mNameToken )
571+ continue ;
572+ if (tok->str () != mNameToken ->str ())
573+ continue ;
574+ if (Token::Match (tok->previous (), " struct|class|enum|union" ))
575+ continue ;
576+ throw InternalError (tok, " recursive typedef encountered" );
577+ }
578+ };
579+
566580 // TODO handle unnamed structs etc
567581 if (Token::Match (start, " const| enum|struct|union|class %name%| {" )) {
568582 const std::pair<const Token*, Token*> rangeBefore (start, Token::findsimplematch (start, " {" ));
@@ -585,24 +599,11 @@ namespace {
585599 }
586600 mNameToken = nameTok;
587601 mEndToken = nameTok->next ();
602+ checkForRecursion ();
588603 return ;
589604 }
590605 }
591606
592- const auto checkForRecursion = [this ]() {
593- if (Token::Match (mTypedefToken , " typedef %name% %name% ;" ))
594- return ;
595- for (const Token *tok = mTypedefToken ; tok != mEndToken ; tok = tok->next ()) {
596- if (tok == mNameToken )
597- continue ;
598- if (tok->str () != mNameToken ->str ())
599- continue ;
600- if (Token::Match (tok->previous (), " struct|class|enum|union" ))
601- continue ;
602- throw InternalError (tok, " recursive typedef encountered" );
603- }
604- };
605-
606607 for (Token* type = start; Token::Match (type, " %name%|*|&|&&" ); type = type->next ()) {
607608 if (type != start && Token::Match (type, " %name% ;" ) && !type->isStandardType ()) {
608609 mRangeType .first = start;
@@ -4548,7 +4549,7 @@ static void setVarIdStructMembers(Token *&tok1,
45484549 return ;
45494550 }
45504551
4551- while (Token::Match (tok->next (), " )| . %name% !!( " )) {
4552+ while (Token::Match (tok->next (), " )| . %name%" )) {
45524553 // Don't set varid for trailing return type
45534554 if (tok->strAt (1 ) == " )" && Token::Match (tok->linkAt (1 )->tokAt (-1 ), " %name%|]" ) && !tok->linkAt (1 )->tokAt (-1 )->isKeyword () &&
45544555 TokenList::isFunctionHead (tok->linkAt (1 ), " {;" )) {
@@ -4570,6 +4571,8 @@ static void setVarIdStructMembers(Token *&tok1,
45704571 std::map<std::string, nonneg int >& members = structMembers[struct_varid];
45714572 const auto it = utils::as_const (members).find (tok->str ());
45724573 if (it == members.cend ()) {
4574+ if (Token::Match (tok, " %name% (" ))
4575+ break ;
45734576 members[tok->str ()] = ++varId;
45744577 tok->varId (varId);
45754578 } else {
0 commit comments