From f3605aedd19fb1f850e94868b89cc51858179e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Fri, 4 Dec 2026 13:42:12 +0100 Subject: [PATCH 1/2] test --- test/testsimplifytypedef.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 8ea0766c977..1c0477432da 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -236,6 +236,7 @@ class TestSimplifyTypedef : public TestFixture { TEST_CASE(simplifyTypedef162); TEST_CASE(simplifyTypedef163); TEST_CASE(simplifyTypedef164); + TEST_CASE(simplifyTypedef165); TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -3903,6 +3904,11 @@ class TestSimplifyTypedef : public TestFixture { ASSERT_EQUALS("struct S { S & operator= ( const S & ) = delete ; } ;", tok(code4)); } + void simplifyTypedef165() { + const char code[] = "struct T {}; void f() { typedef T* T; T x; }"; + ASSERT_EQUALS("struct T { } ; void f ( ) { T * x ; }", tok(code)); + } + void simplifyTypedefFunction1() { { const char code[] = "typedef void (*my_func)();\n" From 42910b81e1e317e3c76cbc035702ac9420639c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Fri, 4 Dec 2026 13:43:39 +0100 Subject: [PATCH 2/2] fix --- lib/tokenize.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 4dbd696f36a..8a90eb80ede 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -579,6 +579,15 @@ namespace { continue; if (Token::Match(tok->previous(), "struct|class|enum|union")) continue; + // shadowing typedef is not recursive + for (const Token *lookback = mTypedefToken->previous(); lookback; lookback = lookback->previous()) { + if (lookback->str() == "}") + lookback = lookback->link(); + else if (lookback->str() == "{") { + mFail = true; + return; + } + } throw InternalError(tok, "recursive typedef encountered"); } };