fix #2844 (typedef causes 'syntax error')

This commit is contained in:
Robert Reif 2011-06-19 17:57:01 -04:00
parent e49763b14f
commit 0bd26a73c4
2 changed files with 41 additions and 13 deletions

View File

@ -1215,12 +1215,22 @@ void Tokenizer::simplifyTypedef()
tok = deleteInvalidTypedef(typeDef); tok = deleteInvalidTypedef(typeDef);
continue; continue;
} }
else if (!Token::Match(tok->tokAt(offset)->link(), ") const| ;|,"))
// function pointer
else if (Token::Match(tok->tokAt(offset), "( * %var% ) ("))
{ {
syntaxError(tok); functionPtr = true;
return; funcStart = tok->tokAt(offset + 1);
funcEnd = tok->tokAt(offset)->link()->previous();
typeName = tok->tokAt(offset)->link()->tokAt(-2);
argStart = tok->tokAt(offset)->link()->next();
argEnd = tok->tokAt(offset)->link()->next()->link();
tok = argEnd->next();
} }
// function
else if (Token::Match(tok->tokAt(offset)->link(), ") const| ;|,"))
{
function = true; function = true;
if (tok->tokAt(offset)->link()->next()->str() == "const") if (tok->tokAt(offset)->link()->next()->str() == "const")
{ {
@ -1234,6 +1244,14 @@ void Tokenizer::simplifyTypedef()
tok = tok->next(); tok = tok->next();
} }
// syntax error
else
{
syntaxError(tok);
return;
}
}
// unhandled typedef, skip it and continue // unhandled typedef, skip it and continue
else else
{ {

View File

@ -259,6 +259,7 @@ private:
TEST_CASE(simplifyTypedef92); // ticket #2736 TEST_CASE(simplifyTypedef92); // ticket #2736
TEST_CASE(simplifyTypedef93); // ticket #2738 TEST_CASE(simplifyTypedef93); // ticket #2738
TEST_CASE(simplifyTypedef94); // ticket #1982 TEST_CASE(simplifyTypedef94); // ticket #1982
TEST_CASE(simplifyTypedef95); // ticket #2844
TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685 TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -5323,6 +5324,15 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void simplifyTypedef95() // ticket #2844
{
const char code1[] = "class symbol_table {\n"
"public:\n"
" typedef expression_error::error_code (*valid_func)(void *cbparam, const char *name, expression_space space);\n"
"};\n";
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedefFunction1() void simplifyTypedefFunction1()
{ {
{ {