Improve fix of #934 (be careful of macros code).
This commit is contained in:
parent
20179673ce
commit
91c6608175
|
@ -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));
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue