Skip to content

Commit 23cc32e

Browse files
Fix #14669 Typedef not simplified: typedef struct T* T; (#8450)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 55493d0 commit 23cc32e

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

lib/tokenize.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,10 +1028,12 @@ bool Tokenizer::isFunctionPointer(const Token* tok) {
10281028
return Token::Match(tok, "%name% ) (");
10291029
}
10301030

1031-
static bool matchCurrentType(const std::string& typeStr, const std::map<int, std::string>& types)
1031+
static bool matchCurrentType(const Token* tok, std::map<int, std::string>& types)
10321032
{
1033+
if (tok->isC())
1034+
return false;
10331035
return std::any_of(types.begin(), types.end(), [&](const std::pair<int, std::string>& element) {
1034-
return typeStr == element.second;
1036+
return tok->str() == element.second;
10351037
});
10361038
}
10371039

@@ -1086,7 +1088,7 @@ void Tokenizer::simplifyTypedef()
10861088
}
10871089

10881090
auto it = typedefs.find(tok->str());
1089-
if (it != typedefs.end() && it->second.canReplace(tok) && !matchCurrentType(tok->str(), inType)) {
1091+
if (it != typedefs.end() && it->second.canReplace(tok) && !matchCurrentType(tok, inType)) {
10901092
std::set<std::string> r;
10911093
std::string originalname;
10921094
while (it != typedefs.end() && r.insert(tok->str()).second) {

test/testsimplifytypedef.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3824,7 +3824,7 @@ class TestSimplifyTypedef : public TestFixture {
38243824
" explicit S2(int& i) : B(i) {}\n"
38253825
" };\n"
38263826
"}\n";
3827-
const char exp[] = "struct S1 { } ; "
3827+
const char exp[] = "struct S1 { } ; " // #12623
38283828
"namespace N { "
38293829
"struct B { "
38303830
"explicit B ( int & i ) ; } ; "
@@ -3833,6 +3833,13 @@ class TestSimplifyTypedef : public TestFixture {
38333833
"} ; "
38343834
"}";
38353835
ASSERT_EQUALS(exp, tok(code));
3836+
3837+
const char code2[] = "typedef stuct T* T;\n" // #14669
3838+
"struct T {\n"
3839+
" T p;\n"
3840+
"};\n";
3841+
const char exp2[] = "struct T { stuct T * p ; } ;";
3842+
ASSERT_EQUALS(exp2, simplifyTypedefC(code2));
38363843
}
38373844

38383845
void simplifyTypedefFunction1() {

0 commit comments

Comments
 (0)