From 66227c4da062584c686d2ffa7b7a914e6a7fa2b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 8 Apr 2012 18:07:11 +0200 Subject: [PATCH] Fixed #3609 (clarifyCondition delivers false positives when using Windows-Traits as a template) --- lib/checkother.cpp | 9 +++++++++ test/testother.cpp | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 3b9d6b3f8..01babac1d 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -189,6 +189,15 @@ void CheckOther::clarifyCondition() Token::simpleMatch(tok2->previous(), "const &"))) continue; + // #3609 - CWinTraits::.. + if (Token::Match(tok->previous(), "%var% <")) { + const Token *tok3 = tok2; + while (Token::Match(tok3, "[&|^] %var%")) + tok3 = tok3->tokAt(2); + if (Token::Match(tok3, ",|>")) + continue; + } + clarifyConditionError(tok,false,true); } } diff --git a/test/testother.cpp b/test/testother.cpp index f911840df..3615563fc 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -128,6 +128,7 @@ private: TEST_CASE(clarifyCondition2); // if (a & b == c) TEST_CASE(clarifyCondition3); // if (! a & b) TEST_CASE(clarifyCondition4); // ticket #3110 + TEST_CASE(clarifyCondition5); // #3609 CWinTraits.. TEST_CASE(bitwiseOnBoolean); // if (bool & bool) TEST_CASE(comparisonOfBoolExpressionWithInt1); @@ -3541,6 +3542,11 @@ private: ASSERT_EQUALS("", errout.str()); } + void clarifyCondition5() { // ticket #3609 (using | in template instantiation) + check("CWinTraits::GetWndStyle(0);"); + ASSERT_EQUALS("", errout.str()); + } + void bitwiseOnBoolean() { // 3062 check("void f(_Bool a, _Bool b) {\n" " if(a & b) {}\n"