From 3db58bb57fb11699f1c5f859902a907764267692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 23 Jun 2012 07:29:49 +0200 Subject: [PATCH] Reviewed C handling in CheckOther::clarifyCondition, never treat x<..> as a template in C files. --- lib/checkother.cpp | 6 ++++-- test/testother.cpp | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) 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());