Robert Reif: Fixed #1164 (only first void operator = found)

This commit is contained in:
Daniel Marjamäki 2009-12-29 07:48:37 +01:00
parent 84ce6ba75a
commit 905533552d
2 changed files with 19 additions and 2 deletions

View File

@ -730,8 +730,10 @@ void CheckClass::noMemset()
void CheckClass::operatorEq()
{
const Token *tok = Token::findmatch(_tokenizer->tokens(), "void operator = (");
if (tok)
const Token *tok2 = _tokenizer->tokens();
const Token *tok;
while ((tok = Token::findmatch(tok2, "void operator = (")))
{
const Token *tok1 = tok;
while (tok1 && !Token::Match(tok1, "class %var%"))
@ -745,6 +747,8 @@ void CheckClass::operatorEq()
break;
tok1 = tok1->previous();
}
tok2 = tok->next();
}
}
//---------------------------------------------------------------------------

View File

@ -122,6 +122,19 @@ private:
"};\n");
ASSERT_EQUALS("", errout.str());
checkOpertorEq("class A\n"
"{\n"
"public:\n"
" void operator=(const& A);\n"
"};\n"
"class B\n"
"{\n"
"public:\n"
" void operator=(const& B);\n"
"};\n");
ASSERT_EQUALS("[test.cpp:4]: (style) 'operator=' should return something\n"
"[test.cpp:9]: (style) 'operator=' should return something\n", errout.str());
}
// Check that base classes have virtual destructors