Function usage: handling 'return foo();' better

This commit is contained in:
Daniel Marjamäki 2008-11-23 14:17:03 +00:00
parent 2db9c34d24
commit bb46a0cc42
2 changed files with 16 additions and 9 deletions

View File

@ -95,8 +95,9 @@ void CheckFunctionUsage::parseTokens( const Tokenizer &tokenizer )
TOKEN::Match(tok, ":: %var% (") || TOKEN::Match(tok, ":: %var% (") ||
TOKEN::Match(tok, "|= %var% (") || TOKEN::Match(tok, "|= %var% (") ||
TOKEN::Match(tok, "&= %var% (") || TOKEN::Match(tok, "&= %var% (") ||
TOKEN::Match(tok, "&& %var% (") || TOKEN::Match(tok, "&& %var% (") ||
TOKEN::Match(tok, "|| %var% (") ) TOKEN::Match(tok, "|| %var% (") ||
TOKEN::Match(tok, "return %var% (") )
funcname = tok->next; funcname = tok->next;
// funcname ( => Assert that the end paranthesis isn't followed by { // funcname ( => Assert that the end paranthesis isn't followed by {

View File

@ -36,7 +36,8 @@ private:
void run() void run()
{ {
TEST_CASE( incondition ); TEST_CASE( incondition );
TEST_CASE( return1 );
} }
void check( const char code[] ) void check( const char code[] )
@ -59,17 +60,22 @@ private:
void incondition() void incondition()
{ {
check( "int f1()\n" check( "int f1()\n"
"{\n"
" f2();\n"
"}\n"
"\n"
"void f2()\n"
"{\n" "{\n"
" if (f1())\n" " if (f1())\n"
" { }\n" " { }\n"
"}\n" ); "}\n" );
std::string err( errout.str() ); std::string err( errout.str() );
ASSERT_EQUALS( std::string(""), errout.str() ); ASSERT_EQUALS( std::string(""), errout.str() );
}
void return1()
{
check( "int f1()\n"
"{\n"
" return f1();\n"
"}\n" );
std::string err( errout.str() );
ASSERT_EQUALS( std::string(""), errout.str() );
} }
}; };