Skip to content

Commit

Permalink
Fix #12700 syntaxError with nested typedef (danmar#6376)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed May 3, 2024
1 parent 55c71f4 commit 9bbc395
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8727,6 +8727,10 @@ void Tokenizer::findGarbageCode() const
syntaxError(tok);
if (tok->str() == "typedef") {
for (const Token* tok2 = tok->next(); tok2 && tok2->str() != ";"; tok2 = tok2->next()) {
if (tok2->str() == "{") {
tok2 = tok2->link();
continue;
}
if (isUnevaluated(tok2)) {
tok2 = tok2->linkAt(1);
continue;
Expand Down
2 changes: 1 addition & 1 deletion test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2516,7 +2516,7 @@ class TestSimplifyTypedef : public TestFixture {

void simplifyTypedef106() { // ticket #3619 (segmentation fault)
const char code[] = "typedef void f ();\ntypedef { f }";
ASSERT_THROW_INTERNAL(tok(code), SYNTAX);
ASSERT_THROW_INTERNAL_EQUALS(tok(code), INTERNAL, "Internal error. AST cyclic dependency.");
}

void simplifyTypedef107() { // ticket #3963 (bad code => segmentation fault)
Expand Down
2 changes: 2 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7149,6 +7149,8 @@ class TestTokenizer : public TestFixture {
ASSERT_NO_THROW(tokenizeAndStringify("template <typename T, int N>\n" // #12659
"constexpr void f(T(&&a)[N]) {}"));

ASSERT_NO_THROW(tokenizeAndStringify("typedef struct { typedef int T; } S;")); // #12700

ignore_errout();
}

Expand Down

0 comments on commit 9bbc395

Please sign in to comment.