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
1 change: 1 addition & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,7 @@ void Tokenizer::simplifyTypedefCpp()
tok2->previous()->str("typedef");
tok2->insertToken(tok2->str());
}
tok2->originalName(tok2->str());
tok2->str(typeStart->str());

// restore qualification if it was removed
Expand Down
2 changes: 1 addition & 1 deletion test/testincompletestatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ class TestIncompleteStatement : public TestFixture {
"void f(int i) {\n"
" (M::N::T)i;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5:5]: (warning) Redundant code: Found unused cast in expression '(char)i'. [constStatement]\n", errout_str());
ASSERT_EQUALS("[test.cpp:5:5]: (warning) Redundant code: Found unused cast in expression '(T)i'. [constStatement]\n", errout_str());

check("void f(int (g)(int a, int b)) {\n" // #10873
" int p = 0, q = 1;\n"
Expand Down
22 changes: 22 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ class TestSimplifyTypedef : public TestFixture {

TEST_CASE(simplifyTypedefOriginalName1);
TEST_CASE(simplifyTypedefOriginalName2);
TEST_CASE(simplifyTypedefOriginalName3);

TEST_CASE(simplifyTypedefTokenColumn1);
TEST_CASE(simplifyTypedefTokenColumn2);
Expand Down Expand Up @@ -4594,6 +4595,27 @@ class TestSimplifyTypedef : public TestFixture {
ASSERT_EQUALS("A", token->originalName());
}

void simplifyTypedefOriginalName3() {
const char code[] = "void f(void) {\n"
" typedef int A;\n"
" A a;\n"
"}\n";
TokenList tokenlist{ settings1, Standards::Language::C };
ASSERT(TokenListHelper::createTokensFromString(tokenlist, code, "file.c"));
TokenizerTest tokenizer(std::move(tokenlist), *this);
tokenizer.createLinks();
tokenizer.simplifyTypedef();

try {
tokenizer.validate();
}
catch (const InternalError&) {
ASSERT_EQUALS_MSG(false, true, "Validation of Tokenizer failed");
}
const Token* token = Token::findsimplematch(tokenizer.list.front(), "int");
ASSERT_EQUALS("A", token->originalName());
}

void simplifyTypedefTokenColumn1() { // #13155
const char code[] = "void foo(void) {\n"
" typedef signed int MY_INT;\n"
Expand Down
Loading