Fixed #2002 (Wrong operator() parsing)

This commit is contained in:
Robert Reif 2010-09-01 06:32:46 +02:00 committed by Daniel Marjamäki
parent e39dda4eed
commit 7a8190e188
2 changed files with 9 additions and 4 deletions

View File

@ -1893,9 +1893,6 @@ void CheckClass::checkConst()
// does the function have a body?
if (func.type == Func::Function && func.hasBody && !func.isFriend && !func.isStatic && !func.isConst && !func.isVirtual)
{
// get function name
const std::string functionName((func.tokenDef->isName() ? "" : "operator") + func.tokenDef->str());
// get last token of return type
const Token *previous = func.tokenDef->isName() ? func.token->previous() : func.token->tokAt(-2);
while (previous->str() == "::")
@ -1969,6 +1966,14 @@ void CheckClass::checkConst()
nest = nest->nestedIn;
}
// get function name
std::string functionName((func.tokenDef->isName() ? "" : "operator") + func.tokenDef->str());
if (func.tokenDef->str() == "(")
functionName += ")";
else if (func.tokenDef->str() == "[")
functionName += "]";
if (func.isInline)
checkConstError(func.token, classname, functionName);
else // not inline

View File

@ -2878,7 +2878,7 @@ private:
" int array[10];\n"
" int const & operator [] (unsigned int index) { return array[index]; }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::operator[' can be const\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::operator[]' can be const\n", errout.str());
}
void const5()