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

@ -96,7 +96,8 @@ 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, "return %var% (") )
funcname = tok->next;
// funcname ( => Assert that the end paranthesis isn't followed by {

View File

@ -37,6 +37,7 @@ private:
void run()
{
TEST_CASE( incondition );
TEST_CASE( return1 );
}
void check( const char code[] )
@ -59,11 +60,6 @@ private:
void incondition()
{
check( "int f1()\n"
"{\n"
" f2();\n"
"}\n"
"\n"
"void f2()\n"
"{\n"
" if (f1())\n"
" { }\n"
@ -71,6 +67,16 @@ private:
std::string err( 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() );
}
};
REGISTER_TEST( TestFunctionUsage )