Improve fix of #934 (be careful of macros code).

This commit is contained in:
Edoardo Prezioso 2011-10-22 20:43:42 +02:00
parent 20179673ce
commit 91c6608175
2 changed files with 17 additions and 0 deletions

View File

@ -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));

View File

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