Skip to content

Commit 9bbc395

Browse files
Fix #12700 syntaxError with nested typedef (#6376)
1 parent 55c71f4 commit 9bbc395

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8727,6 +8727,10 @@ void Tokenizer::findGarbageCode() const
87278727
syntaxError(tok);
87288728
if (tok->str() == "typedef") {
87298729
for (const Token* tok2 = tok->next(); tok2 && tok2->str() != ";"; tok2 = tok2->next()) {
8730+
if (tok2->str() == "{") {
8731+
tok2 = tok2->link();
8732+
continue;
8733+
}
87308734
if (isUnevaluated(tok2)) {
87318735
tok2 = tok2->linkAt(1);
87328736
continue;

test/testsimplifytypedef.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2516,7 +2516,7 @@ class TestSimplifyTypedef : public TestFixture {
25162516

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

25222522
void simplifyTypedef107() { // ticket #3963 (bad code => segmentation fault)

test/testtokenize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7149,6 +7149,8 @@ class TestTokenizer : public TestFixture {
71497149
ASSERT_NO_THROW(tokenizeAndStringify("template <typename T, int N>\n" // #12659
71507150
"constexpr void f(T(&&a)[N]) {}"));
71517151

7152+
ASSERT_NO_THROW(tokenizeAndStringify("typedef struct { typedef int T; } S;")); // #12700
7153+
71527154
ignore_errout();
71537155
}
71547156

0 commit comments

Comments
 (0)