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()); } };