From 6b65b77acf47409a0c36eecb076d226bd7752c9f Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 10 Jun 2010 07:18:55 +0200 Subject: [PATCH] Fixed #1782 ((error) ### Internal error in Cppcheck. Please report it.) --- lib/tokenize.cpp | 13 ++++++++++++- test/testsimplifytokens.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index f7c527292..96fc0c888 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1428,7 +1428,18 @@ void Tokenizer::simplifyTypedef() tok2 = tok2->next(); // skip over name - tok2 = tok2->next(); + if (tok2->next()->str() != ")") + { + tok2 = tok2->next(); + + // check for function and skip over args + if (tok2->next()->str() == "(") + tok2 = tok2->next()->link(); + } + else + { + // syntax error + } tok2->insertToken(")"); Token::createMutualLinks(tok2->next(), tok3); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 01743b60a..c5cea9468 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -200,6 +200,7 @@ private: TEST_CASE(simplifyTypedef49); // ticket #1691 TEST_CASE(simplifyTypedef50); TEST_CASE(simplifyTypedef51); + TEST_CASE(simplifyTypedef52); // ticket #1782 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -4066,6 +4067,31 @@ private: ASSERT_EQUALS(expected, sizeof_(code)); } + void simplifyTypedef52() // ticket #1782 + { + { + const char code[] = "typedef char (* type1)[10];\n" + "type1 foo() { }"; + + // The expected result.. + const std::string expected("; " + "char ( * foo ( ) ) [ 10 ] { }"); + ASSERT_EQUALS(expected, sizeof_(code)); + + checkSimplifyTypedef(code); + ASSERT_EQUALS("", errout.str()); + } + + { + const char code[] = "typedef char (* type1)[10];\n" + "LOCAL(type1) foo() { }"; + + // this is invalid C so just make sure it doesn't generate an internal error + checkSimplifyTypedef(code); + ASSERT_EQUALS("", errout.str()); + } + } + void simplifyTypedefFunction1() { {