Skip to content

Commit dc9bd7f

Browse files
Fix #14966 internalError for valid typedef (#8783)
1 parent 5799d47 commit dc9bd7f

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

lib/tokenize.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,18 @@ namespace {
566566
const auto checkForRecursion = [this]() {
567567
if (Token::Match(mTypedefToken, "typedef %name% %name% ;"))
568568
return;
569+
int nBraces = 0;
569570
for (const Token *tok = mTypedefToken; tok != mEndToken; tok = tok->next()) {
571+
if (tok->str() == "{")
572+
++nBraces;
573+
else if (tok->str() == "}")
574+
--nBraces;
570575
if (tok == mNameToken)
571576
continue;
572577
if (tok->str() != mNameToken->str())
573578
continue;
579+
if (nBraces > 0 && Token::simpleMatch(tok->next(), ";"))
580+
continue;
574581
if (Token::Match(tok->previous(), "struct|class|enum|union"))
575582
continue;
576583
throw InternalError(tok, "recursive typedef encountered");

test/testsimplifytypedef.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3879,6 +3879,9 @@ class TestSimplifyTypedef : public TestFixture {
38793879
void simplifyTypedef164() {
38803880
const char code[] = "typedef struct D{x;}y y;";
38813881
ASSERT_THROW_INTERNAL(tok(code), INTERNAL);
3882+
3883+
const char code2[] = "typedef struct { int t; } t;"; // #14966
3884+
ASSERT_EQUALS("struct t { int t ; } ;", tok(code2));
38823885
}
38833886

38843887
void simplifyTypedefFunction1() {

0 commit comments

Comments
 (0)