From c4750d6d03490369c71c575cb4daaafd639d0216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Tue, 14 Apr 2026 14:42:40 +0200 Subject: [PATCH 1/3] update existing tests --- test/cli/other_test.py | 4 ++-- test/testsimplifytypedef.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/cli/other_test.py b/test/cli/other_test.py index 5c06bd07a94..a49750c82ab 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -420,7 +420,7 @@ def test_addon_misra(tmpdir): assert lines == [ 'Checking {} ...'.format(test_file) ] - assert stderr == '{}:2:1: style: misra violation (use --rule-texts= to get proper output) [misra-c2012-2.3]\ntypedef int MISRA_5_6_VIOLATION;\n^\n'.format(test_file) + assert stderr == '{}:2:13: style: misra violation (use --rule-texts= to get proper output) [misra-c2012-2.3]\ntypedef int MISRA_5_6_VIOLATION;\n ^\n'.format(test_file) def test_addon_y2038(tmpdir): @@ -2674,7 +2674,7 @@ def __test_addon_suppr(tmp_path, extra_args): assert exitcode == 0, stdout assert stdout == '' assert stderr.splitlines() == [ - '{}:4:1: style: misra violation (use --rule-texts= to get proper output) [misra-c2012-2.3]'.format(test_file), + '{}:4:13: style: misra violation (use --rule-texts= to get proper output) [misra-c2012-2.3]'.format(test_file), ] diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 03ac9b45a9e..6d4ce3e7bdd 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -4608,7 +4608,7 @@ class TestSimplifyTypedef : public TestFixture { void typedefInfo1() { const std::string xml = dumpTypedefInfo("typedef int A;\nA x;"); ASSERT_EQUALS(" \n" - " \n" + " \n" " \n", xml); } @@ -4620,7 +4620,7 @@ class TestSimplifyTypedef : public TestFixture { " typedef fp16 ( *pfp16 ) ( void );\n" "}\n"); ASSERT_EQUALS(" \n" - " \n" + " \n" " \n" " \n" " \n" @@ -4632,7 +4632,7 @@ class TestSimplifyTypedef : public TestFixture { " \n" " \n" " \n" - " \n" + " \n" " \n" " \n" " \n" @@ -4670,7 +4670,7 @@ class TestSimplifyTypedef : public TestFixture { "} coord;\n" "coord c;"); ASSERT_EQUALS(" \n" - " \n" + " \n" " \n", xml); } }; From ca422b61a6fddc6bfd5ec76d2d9f2ab0f9523982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Sat, 11 Apr 2026 17:59:51 +0200 Subject: [PATCH 2/3] correct location in typedef-info --- lib/tokenize.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 40dbdf88f9d..6abcae0c13e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1113,11 +1113,12 @@ void Tokenizer::simplifyTypedef() syntaxError(t.second.getTypedefToken()); } else { const Token* const typedefToken = t.second.getTypedefToken(); + const Token* const nameToken = t.second.nameToken(); TypedefInfo typedefInfo; typedefInfo.name = t.second.name(); - typedefInfo.filename = list.file(typedefToken); - typedefInfo.lineNumber = typedefToken->linenr(); - typedefInfo.column = typedefToken->column(); + typedefInfo.filename = list.file(nameToken); + typedefInfo.lineNumber = nameToken->linenr(); + typedefInfo.column = nameToken->column(); if (Token::Match(typedefToken->next(), "struct|enum|class|union %name% {") && typedefToken->strAt(2) == typedefInfo.name) { typedefInfo.tagLine = typedefToken->tokAt(2)->linenr(); typedefInfo.tagColumn = typedefToken->tokAt(2)->column(); From b31604fe2dc319a5ef2d739169311b8f47068a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 13 Apr 2026 14:18:18 +0200 Subject: [PATCH 3/3] add originalName field --- lib/tokenize.cpp | 15 ++++++++++++--- lib/tokenize.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 6abcae0c13e..e95226902cb 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1119,9 +1119,12 @@ void Tokenizer::simplifyTypedef() typedefInfo.filename = list.file(nameToken); typedefInfo.lineNumber = nameToken->linenr(); typedefInfo.column = nameToken->column(); - if (Token::Match(typedefToken->next(), "struct|enum|class|union %name% {") && typedefToken->strAt(2) == typedefInfo.name) { - typedefInfo.tagLine = typedefToken->tokAt(2)->linenr(); - typedefInfo.tagColumn = typedefToken->tokAt(2)->column(); + if (Token::Match(typedefToken->next(), "struct|enum|class|union %name% {")) { + typedefInfo.originalName = typedefToken->strAt(2); + if (typedefToken->strAt(2) == typedefInfo.name) { + typedefInfo.tagLine = typedefToken->tokAt(2)->linenr(); + typedefInfo.tagColumn = typedefToken->tokAt(2)->column(); + } } typedefInfo.used = t.second.isUsed(); typedefInfo.isFunctionPointer = isFunctionPointer(t.second.nameToken()); @@ -6372,6 +6375,12 @@ std::string Tokenizer::dumpTypedefInfo() const outs += typedefInfo.name; outs += "\""; + if (!typedefInfo.originalName.empty()) { + outs += " originalName=\""; + outs += typedefInfo.originalName; + outs += "\""; + } + outs += " file=\""; outs += ErrorLogger::toxml(typedefInfo.filename); outs += "\""; diff --git a/lib/tokenize.h b/lib/tokenize.h index 94f08f9f68e..16c20438e1c 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -693,6 +693,7 @@ class CPPCHECKLIB Tokenizer { }; struct TypedefInfo { std::string name; + std::string originalName; std::string filename; int lineNumber; int column;