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"); } }; 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"