From 91c6608175ef84e5bf18b26350e00d40f5a3389a Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Sat, 22 Oct 2011 20:43:42 +0200 Subject: [PATCH] Improve fix of #934 (be careful of macros code). --- lib/checkother.cpp | 11 +++++++++++ test/testother.cpp | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index fcd7ddb40..c37528c40 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -670,7 +670,18 @@ void CheckOther::switchCaseFallThrough(const Token *tok) void CheckOther::checkCoutCerrMisusage() { bool firstCout = false; + unsigned int roundbraces = 0; for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { + if (tok->str() == "(") + ++roundbraces; + else if (tok->str() == ")") { + if (!roundbraces) + break; + --roundbraces; + } + if (roundbraces) + continue; + if (Token::Match(tok, "std :: cout|cerr")) { if (firstCout && tok->strAt(-1) == "<<" && tok->strAt(3) != ".") { coutCerrMisusageError(tok, tok->strAt(2)); diff --git a/test/testother.cpp b/test/testother.cpp index 338b48dbf..7987765f6 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3782,6 +3782,12 @@ private: " std::cout << std::cout.good();\n" "}"); ASSERT_EQUALS("", errout.str()); + + check( + "void foo() {\n" + " MACRO(std::cout <<, << std::cout)\n" + "}"); + ASSERT_EQUALS("", errout.str()); } };