Fixed false positive in new 'x>-1<5' check when using templates

This commit is contained in:
Daniel Marjamäki 2013-09-07 18:24:35 +02:00
parent 0d246f84ca
commit 51ad747317
2 changed files with 10 additions and 0 deletions

View File

@ -410,6 +410,9 @@ void CheckBool::checkComparisonOfBoolExpressionWithInt()
break; break;
} }
if (Token::Match(lhs,"<|<=|>|>=")) { if (Token::Match(lhs,"<|<=|>|>=")) {
if (_tokenizer->isCPP() && tok->str() == ">" &&
(Token::Match(lhs->previous(), "%var% <") || lhs->str() == ">"))
continue;
while (NULL != (lhs = lhs->previous())) { while (NULL != (lhs = lhs->previous())) {
if ((lhs->isName() && lhs->str() != "return") || lhs->isNumber()) if ((lhs->isName() && lhs->str() != "return") || lhs->isNumber())
continue; continue;

View File

@ -353,6 +353,13 @@ private:
" for(int i = 4; i > -1 < 5 ; --i) {}\n" " for(int i = 4; i > -1 < 5 ; --i) {}\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
// templates
check("struct Tokenizer { TokenList list; };\n"
"void Tokenizer::f() {\n"
" std::list<Token*> locationList;\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
void checkComparisonOfFuncReturningBool1() { void checkComparisonOfFuncReturningBool1() {