Skip to content

Commit 861ce88

Browse files
committed
fix
1 parent 1c14c73 commit 861ce88

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

lib/tokenize.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

0 commit comments

Comments
 (0)