Fixed #2176 (Tokenizer::simplifyTypedef function pointer bug)

This commit is contained in:
Robert Reif 2010-11-06 15:15:50 +01:00 committed by Daniel Marjamäki
parent 0205498a12
commit 8a379d4826
2 changed files with 37 additions and 0 deletions

View File

@ -1371,10 +1371,15 @@ void Tokenizer::simplifyTypedef()
else if (!inOperator && !Token::Match(tok2->next(), "[|>|;"))
{
tok2 = tok2->next();
while (Token::Match(tok2, "*|&") &&
!Token::Match(tok2->next(), ")|>"))
tok2 = tok2->next();
// skip over namespace
while (Token::Match(tok2, "%var% ::"))
tok2 = tok2->tokAt(2);
// skip over typedef parameter
if (tok2->next()->str() == "(")
{

View File

@ -225,6 +225,7 @@ private:
TEST_CASE(simplifyTypedefFunction3);
TEST_CASE(simplifyTypedefFunction4);
TEST_CASE(simplifyTypedefFunction5);
TEST_CASE(simplifyTypedefFunction6);
TEST_CASE(reverseArraySyntax)
TEST_CASE(simplify_numeric_condition)
@ -5083,6 +5084,37 @@ private:
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedefFunction6()
{
const char code[] = "typedef void (*testfp)();\n"
"struct Fred\n"
"{\n"
" testfp get1() { return 0; }\n"
" void ( * get2 ( ) ) ( ) { return 0 ; }\n"
" testfp get3();\n"
" void ( * get4 ( ) ) ( );\n"
"};\n"
"testfp Fred::get3() { return 0; }\n"
"void ( * Fred::get4 ( ) ) ( ) { return 0 ; }\n";
// The expected result..
const std::string expected("; "
"struct Fred "
"{ "
"void ( * get1 ( ) ) ( ) { return 0 ; } "
"void ( * get2 ( ) ) ( ) { return 0 ; } "
"void ( * get3 ( ) ) ( ) ; "
"void ( * get4 ( ) ) ( ) ; "
"} ; "
"void ( * Fred :: get3 ( ) ) ( ) { return 0 ; } "
"void ( * Fred :: get4 ( ) ) ( ) { return 0 ; }");
ASSERT_EQUALS(expected, tok(code, false));
checkSimplifyTypedef(code);
ASSERT_EQUALS("", errout.str());
}
void reverseArraySyntax()
{
ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));