Fixed #2002 (Wrong operator() parsing)
This commit is contained in:
parent
e39dda4eed
commit
7a8190e188
|
@ -1893,9 +1893,6 @@ void CheckClass::checkConst()
|
||||||
// does the function have a body?
|
// does the function have a body?
|
||||||
if (func.type == Func::Function && func.hasBody && !func.isFriend && !func.isStatic && !func.isConst && !func.isVirtual)
|
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
|
// get last token of return type
|
||||||
const Token *previous = func.tokenDef->isName() ? func.token->previous() : func.token->tokAt(-2);
|
const Token *previous = func.tokenDef->isName() ? func.token->previous() : func.token->tokAt(-2);
|
||||||
while (previous->str() == "::")
|
while (previous->str() == "::")
|
||||||
|
@ -1969,6 +1966,14 @@ void CheckClass::checkConst()
|
||||||
nest = nest->nestedIn;
|
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)
|
if (func.isInline)
|
||||||
checkConstError(func.token, classname, functionName);
|
checkConstError(func.token, classname, functionName);
|
||||||
else // not inline
|
else // not inline
|
||||||
|
|
|
@ -2878,7 +2878,7 @@ private:
|
||||||
" int array[10];\n"
|
" int array[10];\n"
|
||||||
" int const & operator [] (unsigned int index) { return array[index]; }\n"
|
" int const & operator [] (unsigned int index) { return array[index]; }\n"
|
||||||
"};\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()
|
void const5()
|
||||||
|
|
Loading…
Reference in New Issue