Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
};
Expand Down
6 changes: 6 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Loading