From f3b2acf585b609795e203f85a6bb074be1f60b47 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 3 Mar 2011 20:32:10 -0500 Subject: [PATCH] really fix #2620 reference of typedef of array not simplified properly --- lib/tokenize.cpp | 11 +++++++++++ test/testsimplifytokens.cpp | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index cd1baa565..76374f498 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1791,6 +1791,17 @@ void Tokenizer::simplifyTypedef() if (!inCast && !inSizeof) tok2 = tok2->next(); + // reference to array? + if (tok2->str() == "&") + { + tok2 = tok2->previous(); + tok2->insertToken("("); + tok2 = tok2->tokAt(3); + tok2->insertToken(")"); + tok2 = tok2->next(); + Token::createMutualLinks(tok2, tok2->tokAt(-3)); + } + tok2 = copyTokens(tok2, arrayStart, arrayEnd); tok2 = tok2->next(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index a546b3654..e1a17d748 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -243,6 +243,7 @@ private: TEST_CASE(simplifyTypedef80); // ticket #2587 TEST_CASE(simplifyTypedef81); // ticket #2603 TEST_CASE(simplifyTypedef82); // ticket #2403 + TEST_CASE(simplifyTypedef83); // ticket #2620 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -4961,6 +4962,18 @@ private: ASSERT_EQUALS("", errout.str()); } + void simplifyTypedef83() // ticket #2620 + { + const char code[] = "typedef char Str[10];\n" + "void f(Str &cl) { }\n"; + + // The expected result.. + const std::string expected("; " + "void f ( char ( & cl ) [ 10 ] ) { }"); + + ASSERT_EQUALS(expected, sizeof_(code)); + } + void simplifyTypedefFunction1() { {