Refactoring: Use continue in loop
This commit is contained in:
parent
32940c023a
commit
da26ef0650
|
@ -52,39 +52,39 @@ void CheckAssert::assertWithSideEffects()
|
||||||
for (const Token* tmp = tok->next(); tmp != endTok; tmp = tmp->next()) {
|
for (const Token* tmp = tok->next(); tmp != endTok; tmp = tmp->next()) {
|
||||||
checkVariableAssignment(tmp, tok->scope());
|
checkVariableAssignment(tmp, tok->scope());
|
||||||
|
|
||||||
if (tmp->tokType() == Token::eFunction) {
|
if (tmp->tokType() != Token::eFunction)
|
||||||
const Function* f = tmp->function();
|
continue;
|
||||||
|
|
||||||
if (f->nestedIn->isClassOrStruct() && !f->isStatic() && !f->isConst())
|
const Function* f = tmp->function();
|
||||||
sideEffectInAssertError(tmp, f->name()); // Non-const member function called
|
if (f->nestedIn->isClassOrStruct() && !f->isStatic() && !f->isConst()) {
|
||||||
else {
|
sideEffectInAssertError(tmp, f->name()); // Non-const member function called
|
||||||
const Scope* scope = f->functionScope;
|
continue;
|
||||||
if (!scope) continue;
|
}
|
||||||
|
const Scope* scope = f->functionScope;
|
||||||
|
if (!scope) continue;
|
||||||
|
|
||||||
for (const Token *tok2 = scope->classStart; tok2 != scope->classEnd; tok2 = tok2->next()) {
|
for (const Token *tok2 = scope->classStart; tok2 != scope->classEnd; tok2 = tok2->next()) {
|
||||||
if (tok2->tokType() != Token::eAssignmentOp && tok2->tokType() != Token::eIncDecOp)
|
if (tok2->tokType() != Token::eAssignmentOp && tok2->tokType() != Token::eIncDecOp)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const Variable* var = tok2->previous()->variable();
|
const Variable* var = tok2->previous()->variable();
|
||||||
if (!var || var->isLocal() || (var->isArgument() && !var->isReference() && !var->isPointer()))
|
if (!var || var->isLocal() || (var->isArgument() && !var->isReference() && !var->isPointer()))
|
||||||
continue; // See ticket #4937. Assigning function arguments not passed by reference is ok.
|
continue; // See ticket #4937. Assigning function arguments not passed by reference is ok.
|
||||||
if (var->isArgument() && var->isPointer() && tok2->strAt(-2) != "*")
|
if (var->isArgument() && var->isPointer() && tok2->strAt(-2) != "*")
|
||||||
continue; // Pointers need to be dereferenced, otherwise there is no error
|
continue; // Pointers need to be dereferenced, otherwise there is no error
|
||||||
|
|
||||||
bool noReturnInScope = true;
|
bool noReturnInScope = true;
|
||||||
for (const Token *rt = scope->classStart; rt != scope->classEnd; rt = rt->next()) {
|
for (const Token *rt = scope->classStart; rt != scope->classEnd; rt = rt->next()) {
|
||||||
if (rt->str() != "return") continue; // find all return statements
|
if (rt->str() != "return") continue; // find all return statements
|
||||||
if (inSameScope(rt, tok2)) {
|
if (inSameScope(rt, tok2)) {
|
||||||
noReturnInScope = false;
|
noReturnInScope = false;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (noReturnInScope) continue;
|
|
||||||
|
|
||||||
sideEffectInAssertError(tmp, f->name());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (noReturnInScope) continue;
|
||||||
|
|
||||||
|
sideEffectInAssertError(tmp, f->name());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tok = endTok;
|
tok = endTok;
|
||||||
|
|
Loading…
Reference in New Issue