diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 644bcd769..0415ab93f 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -147,6 +147,8 @@ void CheckOther::clarifyCondition() if (!_settings->isEnabled("style")) return; + const bool isC = _tokenizer->isC(); + for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { if (Token::Match(tok, "( %var% [=&|^]")) { for (const Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) { @@ -154,7 +156,7 @@ void CheckOther::clarifyCondition() tok2 = tok2->link(); else if (tok2->type() == Token::eComparisonOp) { // This might be a template - if (!_tokenizer->isC() && Token::Match(tok2->previous(), "%var% <")) + if (!isC && Token::Match(tok2->previous(), "%var% <")) break; clarifyConditionError(tok, tok->strAt(2) == "=", false); @@ -189,7 +191,7 @@ void CheckOther::clarifyCondition() continue; // #3609 - CWinTraits::.. - if (Token::Match(tok->previous(), "%var% <")) { + if (!isC && Token::Match(tok->previous(), "%var% <")) { const Token *tok3 = tok2; while (Token::Match(tok3, "[&|^] %var%")) tok3 = tok3->tokAt(2); diff --git a/test/testother.cpp b/test/testother.cpp index 00e913929..776e6e99a 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3548,6 +3548,9 @@ private: check("void f() { A a; }"); ASSERT_EQUALS("", errout.str()); + check("void f() { a(x there are never templates + ASSERT_EQUALS("[test.c:1]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses\n", errout.str()); + check("class A;", "test.C"); ASSERT_EQUALS("", errout.str());