fix #2717 (false positive: syntax error (typedef void f(int) const;))

This commit is contained in:
Robert Reif 2011-04-13 23:24:41 -04:00
parent 50a1f28d86
commit 257197bdd1
2 changed files with 21 additions and 1 deletions

View File

@ -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

View File

@ -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()
{
{