From 51ad747317db9a621ffe6a4875daddc9fd3e5ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 7 Sep 2013 18:24:35 +0200 Subject: [PATCH] Fixed false positive in new 'x>-1<5' check when using templates --- lib/checkbool.cpp | 3 +++ test/testbool.cpp | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lib/checkbool.cpp b/lib/checkbool.cpp index 01184a06c..718258bc4 100644 --- a/lib/checkbool.cpp +++ b/lib/checkbool.cpp @@ -410,6 +410,9 @@ void CheckBool::checkComparisonOfBoolExpressionWithInt() break; } if (Token::Match(lhs,"<|<=|>|>=")) { + if (_tokenizer->isCPP() && tok->str() == ">" && + (Token::Match(lhs->previous(), "%var% <") || lhs->str() == ">")) + continue; while (NULL != (lhs = lhs->previous())) { if ((lhs->isName() && lhs->str() != "return") || lhs->isNumber()) continue; diff --git a/test/testbool.cpp b/test/testbool.cpp index bd9b4b242..e42914857 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -353,6 +353,13 @@ private: " 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()); + + // templates + check("struct Tokenizer { TokenList list; };\n" + "void Tokenizer::f() {\n" + " std::list locationList;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void checkComparisonOfFuncReturningBool1() {