MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / uselessOverrideError

Method uselessOverrideError

lib/checkclass.cpp:3357–3379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3355}
3356
3357void CheckClassImpl::uselessOverrideError(const Function *funcInBase, const Function *funcInDerived, bool isSameCode)
3358{
3359 const std::string functionName = funcInDerived ? ((funcInDerived->isDestructor() ? "~" : "") + funcInDerived->name()) : "";
3360 const std::string funcType = (funcInDerived && funcInDerived->isDestructor()) ? "destructor" : "function";
3361
3362 ErrorPath errorPath;
3363 if (funcInBase && funcInDerived) {
3364 errorPath.emplace_back(funcInBase->tokenDef, "Virtual " + funcType + " in base class");
3365 errorPath.emplace_back(funcInDerived->tokenDef, char(std::toupper(funcType[0])) + funcType.substr(1) + " in derived class");
3366 }
3367
3368 std::string errStr = "\nThe " + funcType + " '$symbol' overrides a " + funcType + " in a base class but ";
3369 if (isSameCode) {
3370 errStr += "is identical to the overridden function";
3371 }
3372 else
3373 errStr += "just delegates back to the base class.";
3374 reportError(std::move(errorPath), Severity::style, "uselessOverride",
3375 "$symbol:" + functionName +
3376 errStr,
3377 CWE(0U) /* Unknown CWE! */,
3378 Certainty::normal);
3379}
3380
3381static const Token* getSingleFunctionCall(const Scope* scope) {
3382 const Token* const start = scope->bodyStart->next();

Callers 1

getErrorMessagesMethod · 0.80

Calls 3

reportErrorFunction · 0.70
CWEClass · 0.70
nameMethod · 0.45

Tested by

no test coverage detected