From 379807a8ea759d99cf199702bf4e4c0730078b5c Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 27 Mar 2014 11:04:31 +0100 Subject: [PATCH] Fixed TODO_ASSERT_EQUAL and #5614 caused by bad simplification of return values. --- lib/tokenize.cpp | 2 +- test/testclass.cpp | 4 ++-- test/testsimplifytokens.cpp | 47 ++++++++++++++++++++++++------------- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c62f33c31..86df0a83c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5107,7 +5107,7 @@ bool Tokenizer::simplifyFunctionReturn() if (tok->str() == "{") tok = tok->link(); - else if (Token::Match(tok, "%var% ( ) { return %bool%|%char%|%num%|%str% ; }")) { + else if (Token::Match(tok, "%var% ( ) { return %bool%|%char%|%num%|%str% ; }") && tok->strAt(-1) != "::") { const Token* const any = tok->tokAt(5); const std::string pattern("(|[|=|%cop% " + tok->str() + " ( ) ;|]|)|%cop%"); diff --git a/test/testclass.cpp b/test/testclass.cpp index 41d4d0757..ce9ced32b 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -2812,8 +2812,8 @@ private: " std::string s;\n" " const std::string & foo();\n" "};\n" - "const std::string & Fred::foo() { return \"\"; }", 0, false, false); - TODO_ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static.\n", "", errout.str()); + "const std::string & Fred::foo() { return \"\"; }"); + ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static.\n", errout.str()); // functions with a function call to a non-const member can't be const.. (#1305) checkConst("class Fred\n" diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 1f4137d91..a654df32e 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -7664,22 +7664,37 @@ private: } 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)); + { + 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)); + } + { + const char code[] = "class Fred {\n" + " std::string s;\n" + " const std::string & foo();\n" + "};\n" + "const std::string & Fred::foo() { return \"\"; }"; + const char expected[] = "class Fred { " + "std :: string s ; " + "const std :: string & foo ( ) ; " + "} ; " + "const std :: string & Fred :: foo ( ) { return \"\" ; }"; + ASSERT_EQUALS(expected, tok(code, false)); + } } void removeVoidFromFunction() {