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() == "{")
|
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%");
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -7664,22 +7664,37 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplifyFunctionReturn() {
|
void simplifyFunctionReturn() {
|
||||||
const char code[] = "typedef void (*testfp)();\n"
|
{
|
||||||
"struct Fred\n"
|
const char code[] = "typedef void (*testfp)();\n"
|
||||||
"{\n"
|
"struct Fred\n"
|
||||||
" testfp get1() { return 0; }\n"
|
"{\n"
|
||||||
" void ( * get2 ( ) ) ( ) { return 0 ; }\n"
|
" testfp get1() { return 0; }\n"
|
||||||
" testfp get3();\n"
|
" void ( * get2 ( ) ) ( ) { return 0 ; }\n"
|
||||||
" void ( * get4 ( ) ) ( );\n"
|
" testfp get3();\n"
|
||||||
"};";
|
" void ( * get4 ( ) ) ( );\n"
|
||||||
const char expected[] = "struct Fred "
|
"};";
|
||||||
"{ "
|
const char expected[] = "struct Fred "
|
||||||
"void ( * get1 ( ) ) ( ) { return 0 ; } "
|
"{ "
|
||||||
"void ( * get2 ( ) ) ( ) { return 0 ; } "
|
"void ( * get1 ( ) ) ( ) { return 0 ; } "
|
||||||
"void ( * get3 ( ) ) ( ) ; "
|
"void ( * get2 ( ) ) ( ) { return 0 ; } "
|
||||||
"void ( * get4 ( ) ) ( ) ; "
|
"void ( * get3 ( ) ) ( ) ; "
|
||||||
"} ;";
|
"void ( * get4 ( ) ) ( ) ; "
|
||||||
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() {
|
||||||
|
|
Loading…
Reference in New Issue