Fixed remaining issue in #3503: Member function taking a function pointer must not be "simplified" to a variable initialization

This commit is contained in:
PKEuS 2014-04-12 10:36:01 +02:00
parent 92839ab4d2
commit 83f4657e69
2 changed files with 25 additions and 2 deletions

View File

@ -6061,9 +6061,14 @@ void Tokenizer::simplifyInitVar()
if (tok->str() == "return")
continue;
if (Token::Match(tok, "class|struct|union| %type% *| %var% ( &| %any% ) ;") ||
Token::Match(tok, "%type% *| %var% ( %type% (")) {
if (Token::Match(tok, "class|struct|union| %type% *| %var% ( &| %any% ) ;")) {
tok = initVar(tok);
} else if (Token::Match(tok, "%type% *| %var% ( %type% (")) {
const Token* tok2 = tok->tokAt(2);
if (!tok2->link())
tok2 = tok2->next();
if (!tok2->link() || (tok2->link()->strAt(1) == ";" && !Token::simpleMatch(tok2->linkAt(2), ") (")))
tok = initVar(tok);
} else if (Token::Match(tok, "class|struct|union| %type% *| %var% ( &| %any% ) ,")) {
Token *tok1 = tok;
while (tok1->str() != ",")

View File

@ -63,6 +63,7 @@ private:
TEST_CASE(tokenize28); // #4725 (writing asm() around "^{}")
TEST_CASE(tokenize29); // #5506 (segmentation fault upon invalid code)
TEST_CASE(tokenize30); // #5356 (segmentation fault upon invalid code)
TEST_CASE(tokenize31); // #3503 (Wrong handling of member function taking function pointer as argument)
// don't freak out when the syntax is wrong
TEST_CASE(wrong_syntax1);
@ -841,6 +842,23 @@ private:
tokenizeAndStringify("struct template<int { = }; > struct B { }; B < 0 > b;");
}
// #3503 - don't "simplify" SetFunction member function to a variable
void tokenize31() {
ASSERT_EQUALS("struct TTestClass { TTestClass ( ) { }\n"
"void SetFunction ( Other * m_f ) { }\n"
"} ;",
tokenizeAndStringify("struct TTestClass { TTestClass() { }\n"
" void SetFunction(Other(*m_f)()) { }\n"
"};"));
ASSERT_EQUALS("struct TTestClass { TTestClass ( ) { }\n"
"void SetFunction ( Other * m_f ) ;\n"
"} ;",
tokenizeAndStringify("struct TTestClass { TTestClass() { }\n"
" void SetFunction(Other(*m_f)());\n"
"};"));
}
void wrong_syntax1() {
{
const char code[] ="TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))";