From 030b12057fed82ca5969f5338b5d3ecb904f2962 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 17 Jan 2025 19:45:44 +0100 Subject: [PATCH 1/2] Update testsimplifytypedef.cpp --- test/testsimplifytypedef.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 188ec37c3e5..ffe1102a882 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -223,6 +223,7 @@ class TestSimplifyTypedef : public TestFixture { TEST_CASE(simplifyTypedef155); TEST_CASE(simplifyTypedef156); TEST_CASE(simplifyTypedef157); + TEST_CASE(simplifyTypedef158); TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -3773,6 +3774,16 @@ class TestSimplifyTypedef : public TestFixture { ASSERT_EQUALS(exp, tok(code)); } + void simplifyTypedef158() { + const char code[] = "void f() {\n" + " typedef const char* const triple[3];\n" + " static const triple data[] = { {\"a\" , \"b\" , \"c\" } };\n" + "}\n"; + const char exp[] = "void f ( ) { static const char * const data [ ] [ 3 ] = { { \"a\" , \"b\" , \"c\" } } ; }"; + const char cur[] = "void f ( ) { static const char * const const data [ ] [ 3 ] = { { \"a\" , \"b\" , \"c\" } } ; }"; + TODO_ASSERT_EQUALS(exp, cur, tok(code)); + } + void simplifyTypedefFunction1() { { const char code[] = "typedef void (*my_func)();\n" From 376b61af37d37682d9e2956f14d97c7191a2d17f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 17 Jan 2025 19:46:43 +0100 Subject: [PATCH 2/2] Update tokenize.cpp --- lib/tokenize.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 77a9d265c13..b054e8c569e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2016,7 +2016,7 @@ void Tokenizer::simplifyTypedefCpp() const bool isPointerTypeCall = !inOperator && Token::Match(tok2, "%name% ( )") && !pointers.empty(); // start substituting at the typedef name by replacing it with the type - const Token * const location = tok2; + const Token* location = tok2; for (Token* tok3 = typeStart; tok3 && (tok3->str() != ";"); tok3 = tok3->next()) tok3->isSimplifiedTypedef(true); if (isPointerTypeCall) { @@ -2081,6 +2081,7 @@ void Tokenizer::simplifyTypedefCpp() if (constTok && !functionPtr) { tok2 = simplifyTypedefInsertToken(tok2, "const", location); constTok->deleteThis(); + location = constTok; } }