Skip to content

Commit

Permalink
Fix #13155 (Tokenizer::simplifyTypedef does not set info correctly fo…
Browse files Browse the repository at this point in the history
…r typedef in function)
  • Loading branch information
danmar committed Dec 1, 2024
1 parent 588ca87 commit 6c81d70
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2057,10 +2057,13 @@ void Tokenizer::simplifyTypedefCpp()
removed1.resize(idx);
}
}
replStart->isSimplifiedTypedef(true);
Token* constTok = Token::simpleMatch(tok2->previous(), "const") ? tok2->previous() : nullptr;
// add remainder of type
tok2 = TokenList::copyTokens(tok2, typeStart->next(), typeEnd);
for (Token* tok3 = replStart; tok3 != tok2->next(); tok3 = tok3->next()) {
tok3->column(replStart->column());
tok3->isSimplifiedTypedef(true);
}

if (!pointers.empty()) {
for (const std::string &p : pointers) {
Expand Down
20 changes: 20 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ class TestSimplifyTypedef : public TestFixture {

TEST_CASE(simplifyTypedefOriginalName);

TEST_CASE(simplifyTypedefTokenColumn);

TEST_CASE(typedefInfo1);

TEST_CASE(typedefInfo2);
Expand Down Expand Up @@ -4454,6 +4456,24 @@ class TestSimplifyTypedef : public TestFixture {
ASSERT_EQUALS("rFunctionPointer_fp", token->originalName());
}

void simplifyTypedefTokenColumn() { // #13155
const char code[] = "void foo(void) {\n"
" typedef signed int MY_INT;\n"
" MY_INT x = 0;\n"
"}";

Tokenizer tokenizer(settings1, *this);
std::istringstream istr(code);
ASSERT(tokenizer.list.createTokens(istr, "file.c"));
tokenizer.createLinks();
tokenizer.simplifyTypedef();

const Token* x = Token::findsimplematch(tokenizer.list.front(), "x");
const Token* type = x->previous();
ASSERT_EQUALS("int", type->str());
ASSERT_EQUALS(5, type->column());
}

void typedefInfo1() {
const std::string xml = dumpTypedefInfo("typedef int A;\nA x;");
ASSERT_EQUALS(" <typedef-info>\n"
Expand Down

0 comments on commit 6c81d70

Please sign in to comment.