Redo refactoring of CheckClass::checkConst.
This commit is contained in:
parent
530a05e40e
commit
54db79305b
|
@ -1692,11 +1692,7 @@ void CheckClass::checkConst()
|
||||||
|
|
||||||
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
|
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
|
||||||
// does the function have a body?
|
// does the function have a body?
|
||||||
if (func->type != Function::eFunction || !func->hasBody())
|
if (func->type != Function::eFunction || !func->hasBody() || func->isFriend() || func->isStatic() || func->isVirtual())
|
||||||
continue;
|
|
||||||
|
|
||||||
// don't warn for friend/static/virtual methods
|
|
||||||
if (func->isFriend() || func->isStatic() || func->isVirtual())
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// get last token of return type
|
// get last token of return type
|
||||||
|
@ -1732,36 +1728,36 @@ void CheckClass::checkConst()
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if base class function is virtual
|
// check if base class function is virtual
|
||||||
if (!scope->definedType->derivedFrom.empty() && !func->isImplicitlyVirtual(true))
|
if (!scope->definedType->derivedFrom.empty()) {
|
||||||
continue;
|
if (func->isImplicitlyVirtual(true))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
bool memberAccessed = false;
|
bool memberAccessed = false;
|
||||||
// if nothing non-const was found. write error..
|
// if nothing non-const was found. write error..
|
||||||
if (!checkConstFunc(scope, &*func, memberAccessed))
|
if (checkConstFunc(scope, &*func, memberAccessed)) {
|
||||||
continue;
|
std::string classname = scope->className;
|
||||||
|
const Scope *nest = scope->nestedIn;
|
||||||
|
while (nest && nest->type != Scope::eGlobal) {
|
||||||
|
classname = std::string(nest->className + "::" + classname);
|
||||||
|
nest = nest->nestedIn;
|
||||||
|
}
|
||||||
|
|
||||||
if (func->isConst() && (memberAccessed || func->isOperator()))
|
// get function name
|
||||||
continue;
|
std::string functionName = (func->tokenDef->isName() ? "" : "operator") + func->tokenDef->str();
|
||||||
|
|
||||||
std::string classname = scope->className;
|
if (func->tokenDef->str() == "(")
|
||||||
const Scope *nest = scope->nestedIn;
|
functionName += ")";
|
||||||
while (nest && nest->type != Scope::eGlobal) {
|
else if (func->tokenDef->str() == "[")
|
||||||
classname = std::string(nest->className + "::" + classname);
|
functionName += "]";
|
||||||
nest = nest->nestedIn;
|
|
||||||
|
if (!func->isConst() || (!memberAccessed && !func->isOperator())) {
|
||||||
|
if (func->isInline())
|
||||||
|
checkConstError(func->token, classname, functionName, !memberAccessed && !func->isOperator());
|
||||||
|
else // not inline
|
||||||
|
checkConstError2(func->token, func->tokenDef, classname, functionName, !memberAccessed && !func->isOperator());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, !memberAccessed && !func->isOperator());
|
|
||||||
else // not inline
|
|
||||||
checkConstError2(func->token, func->tokenDef, classname, functionName, !memberAccessed && !func->isOperator());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue