Skip to content

Commit

Permalink
performance, simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Apr 8, 2024
1 parent 2dde486 commit b7e6af6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3305,6 +3305,8 @@ void CheckClass::checkUselessOverride()
}

static const Variable* getSingleReturnVar(const Scope* scope) {
if (!scope)
return nullptr;
const Token* const start = scope->bodyStart->next();
const Token* const end = Token::findsimplematch(start, ";", 1, scope->bodyEnd);
if (!end || end->next() != scope->bodyEnd)
Expand All @@ -3323,8 +3325,6 @@ void CheckClass::checkReturnByReference()

for (const Scope* classScope : mSymbolDatabase->classAndStructScopes) {
for (const Function& func : classScope->functionList) {
if (!func.functionScope)
continue;
if (Function::returnsPointer(&func) || Function::returnsReference(&func) || Function::returnsStandardType(&func))
continue;
if (const Variable* var = getSingleReturnVar(func.functionScope)) {
Expand All @@ -3349,7 +3349,7 @@ void CheckClass::returnByReferenceError(const Function* func, const Variable* va
{
const Token* tok = func ? func->tokenDef : nullptr;
const std::string message = "Function '" + (func ? func->name() : "") + "()' should return member '" + (var ? var->name() : "") + "' by const reference.";
reportError(tok, Severity::style, "returnByReference", message);
reportError(tok, Severity::performance, "returnByReference", message);
}

void CheckClass::checkThisUseAfterFree()
Expand Down

0 comments on commit b7e6af6

Please sign in to comment.