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
8 changes: 5 additions & 3 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,10 +1028,12 @@ bool Tokenizer::isFunctionPointer(const Token* tok) {
return Token::Match(tok, "%name% ) (");
}

static bool matchCurrentType(const std::string& typeStr, const std::map<int, std::string>& types)
static bool matchCurrentType(const Token* tok, std::map<int, std::string>& types)
{
if (tok->isC())
return false;
return std::any_of(types.begin(), types.end(), [&](const std::pair<int, std::string>& element) {
return typeStr == element.second;
return tok->str() == element.second;
});
}

Expand Down Expand Up @@ -1086,7 +1088,7 @@ void Tokenizer::simplifyTypedef()
}

auto it = typedefs.find(tok->str());
if (it != typedefs.end() && it->second.canReplace(tok) && !matchCurrentType(tok->str(), inType)) {
if (it != typedefs.end() && it->second.canReplace(tok) && !matchCurrentType(tok, inType)) {
std::set<std::string> r;
std::string originalname;
while (it != typedefs.end() && r.insert(tok->str()).second) {
Expand Down
9 changes: 8 additions & 1 deletion test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3824,7 +3824,7 @@ class TestSimplifyTypedef : public TestFixture {
" explicit S2(int& i) : B(i) {}\n"
" };\n"
"}\n";
const char exp[] = "struct S1 { } ; "
const char exp[] = "struct S1 { } ; " // #12623
"namespace N { "
"struct B { "
"explicit B ( int & i ) ; } ; "
Expand All @@ -3833,6 +3833,13 @@ class TestSimplifyTypedef : public TestFixture {
"} ; "
"}";
ASSERT_EQUALS(exp, tok(code));

const char code2[] = "typedef stuct T* T;\n" // #14669
"struct T {\n"
" T p;\n"
"};\n";
const char exp2[] = "struct T { stuct T * p ; } ;";
ASSERT_EQUALS(exp2, simplifyTypedefC(code2));
}

void simplifyTypedefFunction1() {
Expand Down
Loading