Fixed TODO_ASSERT_EQUAL and #5614 caused by bad simplification of return values.

This commit is contained in:
PKEuS 2014-03-27 11:04:31 +01:00
parent 2248cdfea0
commit 379807a8ea
3 changed files with 34 additions and 19 deletions

View File

@ -5107,7 +5107,7 @@ bool Tokenizer::simplifyFunctionReturn()
if (tok->str() == "{") if (tok->str() == "{")
tok = tok->link(); 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 Token* const any = tok->tokAt(5);
const std::string pattern("(|[|=|%cop% " + tok->str() + " ( ) ;|]|)|%cop%"); const std::string pattern("(|[|=|%cop% " + tok->str() + " ( ) ;|]|)|%cop%");

View File

@ -2812,8 +2812,8 @@ private:
" std::string s;\n" " std::string s;\n"
" const std::string & foo();\n" " const std::string & foo();\n"
"};\n" "};\n"
"const std::string & Fred::foo() { return \"\"; }", 0, false, false); "const std::string & Fred::foo() { return \"\"; }");
TODO_ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static.\n", "", errout.str()); 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) // functions with a function call to a non-const member can't be const.. (#1305)
checkConst("class Fred\n" checkConst("class Fred\n"

View File

@ -7664,6 +7664,7 @@ private:
} }
void simplifyFunctionReturn() { void simplifyFunctionReturn() {
{
const char code[] = "typedef void (*testfp)();\n" const char code[] = "typedef void (*testfp)();\n"
"struct Fred\n" "struct Fred\n"
"{\n" "{\n"
@ -7681,6 +7682,20 @@ private:
"} ;"; "} ;";
ASSERT_EQUALS(expected, tok(code, false)); 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() { void removeVoidFromFunction() {
ASSERT_EQUALS("void foo ( ) ;", tok("void foo(void);")); ASSERT_EQUALS("void foo ( ) ;", tok("void foo(void);"));