From bb20c0504ed67ef2693e0a520a451de7953c6f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 13 Sep 2017 22:46:36 +0200 Subject: [PATCH] CheckCondition: Fix FP in daca (iqtree) 'in >> ch' --- lib/checkcondition.cpp | 7 ++++++- test/testcondition.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index efa695067..20a116c6a 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -646,8 +646,13 @@ void CheckCondition::multiCondition2() if (Token::Match(parent->astParent(), "%assign%")) break; } - if (Token::Match(tok, "%name% <<|>>") && (!tok->valueType() || !tok->valueType()->isIntegral())) + if (_tokenizer->isCPP() && Token::Match(tok, "%name% <<|>>") && (!tok->valueType() || !tok->valueType()->isIntegral())) break; + if (_tokenizer->isCPP() && Token::simpleMatch(tok->previous(), ">>")) { + const Token *rhs = tok->previous()->astOperand1(); + if (!rhs || !rhs->valueType() || !rhs->valueType()->isIntegral()) + break; + } if (Token::Match(tok, "%name% [")) { const Token *tok2 = tok->linkAt(1); while (Token::simpleMatch(tok2, "] [")) diff --git a/test/testcondition.cpp b/test/testcondition.cpp index d907e20f4..28d80e7f1 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -1859,6 +1859,16 @@ private: " if(++start<100 && 10<=section[start]) { }\n" "}"); ASSERT_EQUALS("", errout.str()); + + // daca iqtree + check("void readNCBITree(std::istream &in) {\n" + " char ch;\n" + " in >> ch;\n" + " if (ch != '|') return;\n" + " in >> ch;\n" + " if (ch != '|') {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } // clarify conditions with = and comparison