Skip to content

Commit dbde189

Browse files
authored
Fix #14946: originalName in dumpfile missing for local typedefs (#8760)
1 parent cd55e08 commit dbde189

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,6 +2044,7 @@ void Tokenizer::simplifyTypedefCpp()
20442044
tok2->previous()->str("typedef");
20452045
tok2->insertToken(tok2->str());
20462046
}
2047+
tok2->originalName(tok2->str());
20472048
tok2->str(typeStart->str());
20482049

20492050
// restore qualification if it was removed

test/testincompletestatement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ class TestIncompleteStatement : public TestFixture {
492492
"void f(int i) {\n"
493493
" (M::N::T)i;\n"
494494
"}\n");
495-
ASSERT_EQUALS("[test.cpp:5:5]: (warning) Redundant code: Found unused cast in expression '(char)i'. [constStatement]\n", errout_str());
495+
ASSERT_EQUALS("[test.cpp:5:5]: (warning) Redundant code: Found unused cast in expression '(T)i'. [constStatement]\n", errout_str());
496496

497497
check("void f(int (g)(int a, int b)) {\n" // #10873
498498
" int p = 0, q = 1;\n"

test/testsimplifytypedef.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ class TestSimplifyTypedef : public TestFixture {
256256

257257
TEST_CASE(simplifyTypedefOriginalName1);
258258
TEST_CASE(simplifyTypedefOriginalName2);
259+
TEST_CASE(simplifyTypedefOriginalName3);
259260

260261
TEST_CASE(simplifyTypedefTokenColumn1);
261262
TEST_CASE(simplifyTypedefTokenColumn2);
@@ -4600,6 +4601,21 @@ class TestSimplifyTypedef : public TestFixture {
46004601
ASSERT_EQUALS("A", token->originalName());
46014602
}
46024603

4604+
void simplifyTypedefOriginalName3() {
4605+
const char code[] = "void f(void) {\n"
4606+
" typedef int A;\n"
4607+
" A a;\n"
4608+
"}\n";
4609+
TokenList tokenlist{ settings1, Standards::Language::C };
4610+
ASSERT(TokenListHelper::createTokensFromString(tokenlist, code, "file.c"));
4611+
TokenizerTest tokenizer(std::move(tokenlist), *this);
4612+
tokenizer.createLinks();
4613+
tokenizer.simplifyTypedef();
4614+
ASSERT_NO_THROW(tokenizer.validate());
4615+
const Token* token = Token::findsimplematch(tokenizer.list.front(), "int");
4616+
ASSERT_EQUALS("A", token->originalName());
4617+
}
4618+
46034619
void simplifyTypedefTokenColumn1() { // #13155
46044620
const char code[] = "void foo(void) {\n"
46054621
" typedef signed int MY_INT;\n"

0 commit comments

Comments
 (0)