From 9bbc395a677ff8ad4c1d20be3ad735cec060104c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 3 May 2024 12:29:46 +0200 Subject: [PATCH] Fix #12700 syntaxError with nested typedef (#6376) --- lib/tokenize.cpp | 4 ++++ test/testsimplifytypedef.cpp | 2 +- test/testtokenize.cpp | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 432d43f4463..35c60fc5ccf 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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; diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 37496dfe339..44abd19da3c 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -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) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b07114d7f79..13969de1430 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7149,6 +7149,8 @@ class TestTokenizer : public TestFixture { ASSERT_NO_THROW(tokenizeAndStringify("template \n" // #12659 "constexpr void f(T(&&a)[N]) {}")); + ASSERT_NO_THROW(tokenizeAndStringify("typedef struct { typedef int T; } S;")); // #12700 + ignore_errout(); }