From 431201dd67f50b55a983818457ee7eda47ba3ab6 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sat, 6 Nov 2010 06:53:09 +0100 Subject: [PATCH] Fixed #2174 (Tokenizer::simplifyFunctionReturn bug) --- lib/tokenize.cpp | 2 +- test/testsimplifytokens.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b45e3ded2..0862ac03b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4951,7 +4951,7 @@ bool Tokenizer::simplifyFunctionReturn() else if (tok->str() == "}") --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; pattern << "[(=+-*/] " << tok->str() << " ( ) [;)+-*/]"; diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 12ca7cbf8..f5e8e5bda 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -291,6 +291,8 @@ private: TEST_CASE(simplifyFunctorCall); TEST_CASE(redundant_semicolon); + + TEST_CASE(simplifyFunctionReturn); } 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() { 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)