From c949a29d1e526acae7e9d5f9f7dcf650c5bd6336 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Mon, 5 Jul 2010 23:03:54 +0200 Subject: [PATCH] Fixed #1821 (simplifyTypedef: better typedef support) --- lib/tokenize.cpp | 2 +- test/testsimplifytokens.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a694bc021..9330bd506 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -842,7 +842,7 @@ void Tokenizer::simplifyTypedef() } // check for pointers and references - while (Token::Match(tok->tokAt(offset), "*|&")) + while (Token::Match(tok->tokAt(offset), "*|&|const")) pointers.push_back(tok->tokAt(offset++)->str()); if (Token::Match(tok->tokAt(offset), "%type%")) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index aae00e142..759daad78 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -205,6 +205,7 @@ private: TEST_CASE(simplifyTypedef52); // ticket #1782 TEST_CASE(simplifyTypedef53); // ticket #1801 TEST_CASE(simplifyTypedef54); // ticket #1814 + TEST_CASE(simplifyTypedef55); TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -4222,6 +4223,27 @@ private: ASSERT_EQUALS("", errout.str()); } + void simplifyTypedef55() + { + const char code[] = "typedef volatile unsigned long * const hwreg_t ;\n" + "typedef void *const t1[2];\n" + "typedef int*const *_Iterator;\n" + "hwreg_t v1;\n" + "t1 v2;\n" + "_Iterator v3;\n"; + + // The expected result.. + const std::string expected("; ; ; " + "long * v1 ; " + "void * v2 [ 2 ] ; " + "int * * v3 ;"); + ASSERT_EQUALS(expected, sizeof_(code)); + + // Check for output.. + checkSimplifyTypedef(code); + ASSERT_EQUALS("", errout.str()); + } + void simplifyTypedefFunction1() { {