Variable usage: Fixed false positives (tmp1 ? tmp2 : tmp3)

This commit is contained in:
Daniel Marjamäki 2009-01-04 17:23:04 +00:00
parent 76e2aea0f5
commit 9ea852eb0e
2 changed files with 16 additions and 3 deletions

View File

@ -809,7 +809,7 @@ static bool isOp(const Token *tok)
tok->str() == ">" || tok->str() == ">" ||
tok->str() == ">=" || tok->str() == ">=" ||
tok->str() == "<<" || tok->str() == "<<" ||
Token::Match(tok, "[+-*/%&|,[])]"))); Token::Match(tok, "[+-*/%&|,[])?:]")));
} }
void CheckOther::functionVariableUsage() void CheckOther::functionVariableUsage()

View File

@ -66,6 +66,7 @@ private:
TEST_CASE( localvarMod ); // Usage with modulo TEST_CASE( localvarMod ); // Usage with modulo
TEST_CASE( localvarIf ); // Usage in if TEST_CASE( localvarIf ); // Usage in if
TEST_CASE( localvarIfElse ); // return tmp1 ? tmp2 : tmp3;
} }
void structmember1() void structmember1()
@ -223,6 +224,18 @@ private:
ASSERT_EQUALS( std::string(""), errout.str() ); ASSERT_EQUALS( std::string(""), errout.str() );
} }
void localvarIfElse()
{
functionVariableUsage( "int foo()\n"
"{\n"
" int tmp1 = 1;\n"
" int tmp2 = 2;\n"
" int tmp3 = 3;\n"
" return tmp1 ? tmp2 : tmp3;\n"
"}\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}
}; };