Fixed #2174 (Tokenizer::simplifyFunctionReturn bug)
This commit is contained in:
parent
52faadda89
commit
431201dd67
|
@ -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() << " ( ) [;)+-*/]";
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue