Fixed TODO_ASSERT_EQUAL and #5614 caused by bad simplification of return values.
This commit is contained in:
parent
2248cdfea0
commit
379807a8ea
|
@ -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%");
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue