Fixed #2174 (Tokenizer::simplifyFunctionReturn bug)

This commit is contained in:
Robert Reif 2010-11-06 06:53:09 +01:00 committed by Daniel Marjamäki
parent 52faadda89
commit 431201dd67
2 changed files with 24 additions and 1 deletions

View File

@ -4951,7 +4951,7 @@ bool Tokenizer::simplifyFunctionReturn()
else if (tok->str() == "}") else if (tok->str() == "}")
--indentlevel; --indentlevel;
else if (indentlevel == 0 && Token::Match(tok, "%var% ( ) { return %num% ; }")) else if (indentlevel == 0 && Token::Match(tok, "%var% ( ) { return %num% ; }") && tok->str() != ")")
{ {
std::ostringstream pattern; std::ostringstream pattern;
pattern << "[(=+-*/] " << tok->str() << " ( ) [;)+-*/]"; pattern << "[(=+-*/] " << tok->str() << " ( ) [;)+-*/]";

View File

@ -291,6 +291,8 @@ private:
TEST_CASE(simplifyFunctorCall); TEST_CASE(simplifyFunctorCall);
TEST_CASE(redundant_semicolon); TEST_CASE(redundant_semicolon);
TEST_CASE(simplifyFunctionReturn);
} }
std::string tok(const char code[], bool simplify = true) std::string tok(const char code[], bool simplify = true)
@ -5934,6 +5936,27 @@ private:
ASSERT_EQUALS("void f ( ) { ; }", tok("void f() { ; }", false)); ASSERT_EQUALS("void f ( ) { ; }", tok("void f() { ; }", false));
ASSERT_EQUALS("void f ( ) { ; }", tok("void f() { do { ; } while (0); }", true)); ASSERT_EQUALS("void f ( ) { ; }", tok("void f() { do { ; } while (0); }", true));
} }
void simplifyFunctionReturn()
{
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"
"};";
const char expected[] = "; "
"struct Fred "
"{ "
"void ( * get1 ( ) ) ( ) { return 0 ; } "
"void ( * get2 ( ) ) ( ) { return 0 ; } "
"void ( * get3 ( ) ) ( ) ; "
"void ( * get4 ( ) ) ( ) ; "
"} ;";
ASSERT_EQUALS(expected, tok(code, false));
}
}; };
REGISTER_TEST(TestSimplifyTokens) REGISTER_TEST(TestSimplifyTokens)