diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index df176c3a0..6b7937b86 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1202,16 +1202,23 @@ void Tokenizer::simplifyTypedef() tok = deleteInvalidTypedef(typeDef); continue; } - else if (!Token::Match(tok->tokAt(offset)->link(), ") ;|,")) + else if (!Token::Match(tok->tokAt(offset)->link(), ") const| ;|,")) { syntaxError(tok); return; } function = true; + if (tok->tokAt(offset)->link()->next()->str() == "const") + { + specStart = tok->tokAt(offset)->link()->next(); + specEnd = specStart; + } argStart = tok->tokAt(offset); argEnd = tok->tokAt(offset)->link(); tok = argEnd->next(); + if (specStart) + tok = tok->next(); } // unhandled typedef, skip it and continue diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 85dec647f..af291b714 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -252,6 +252,7 @@ private: TEST_CASE(simplifyTypedef86); // ticket #2581 TEST_CASE(simplifyTypedef87); // ticket #2651 TEST_CASE(simplifyTypedef88); // ticket #2675 + TEST_CASE(simplifyTypedef89); // ticket #2717 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -5087,6 +5088,18 @@ private: ASSERT_EQUALS("", errout.str()); } + void simplifyTypedef89() // ticket #2717 + { + const char code[] = "class Fred {\n" + " typedef void f(int) const;\n" + " f func;\n" + "};\n"; + const char expected[] = "class Fred { ; void func ( int ) const ; } ;"; + checkSimplifyTypedef(code); + ASSERT_EQUALS(expected, sizeof_(code)); + ASSERT_EQUALS("", errout.str()); + } + void simplifyTypedefFunction1() { {