Skip to content

Commit da26ef0

Browse files
committed
Refactoring: Use continue in loop
1 parent 32940c0 commit da26ef0

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

lib/checkassert.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -52,39 +52,39 @@ void CheckAssert::assertWithSideEffects()
5252
for (const Token* tmp = tok->next(); tmp != endTok; tmp = tmp->next()) {
5353
checkVariableAssignment(tmp, tok->scope());
5454

55-
if (tmp->tokType() == Token::eFunction) {
56-
const Function* f = tmp->function();
57-
58-
if (f->nestedIn->isClassOrStruct() && !f->isStatic() && !f->isConst())
59-
sideEffectInAssertError(tmp, f->name()); // Non-const member function called
60-
else {
61-
const Scope* scope = f->functionScope;
62-
if (!scope) continue;
63-
64-
for (const Token *tok2 = scope->classStart; tok2 != scope->classEnd; tok2 = tok2->next()) {
65-
if (tok2->tokType() != Token::eAssignmentOp && tok2->tokType() != Token::eIncDecOp)
66-
continue;
67-
68-
const Variable* var = tok2->previous()->variable();
69-
if (!var || var->isLocal() || (var->isArgument() && !var->isReference() && !var->isPointer()))
70-
continue; // See ticket #4937. Assigning function arguments not passed by reference is ok.
71-
if (var->isArgument() && var->isPointer() && tok2->strAt(-2) != "*")
72-
continue; // Pointers need to be dereferenced, otherwise there is no error
73-
74-
bool noReturnInScope = true;
75-
for (const Token *rt = scope->classStart; rt != scope->classEnd; rt = rt->next()) {
76-
if (rt->str() != "return") continue; // find all return statements
77-
if (inSameScope(rt, tok2)) {
78-
noReturnInScope = false;
79-
break;
80-
}
81-
}
82-
if (noReturnInScope) continue;
83-
84-
sideEffectInAssertError(tmp, f->name());
55+
if (tmp->tokType() != Token::eFunction)
56+
continue;
57+
58+
const Function* f = tmp->function();
59+
if (f->nestedIn->isClassOrStruct() && !f->isStatic() && !f->isConst()) {
60+
sideEffectInAssertError(tmp, f->name()); // Non-const member function called
61+
continue;
62+
}
63+
const Scope* scope = f->functionScope;
64+
if (!scope) continue;
65+
66+
for (const Token *tok2 = scope->classStart; tok2 != scope->classEnd; tok2 = tok2->next()) {
67+
if (tok2->tokType() != Token::eAssignmentOp && tok2->tokType() != Token::eIncDecOp)
68+
continue;
69+
70+
const Variable* var = tok2->previous()->variable();
71+
if (!var || var->isLocal() || (var->isArgument() && !var->isReference() && !var->isPointer()))
72+
continue; // See ticket #4937. Assigning function arguments not passed by reference is ok.
73+
if (var->isArgument() && var->isPointer() && tok2->strAt(-2) != "*")
74+
continue; // Pointers need to be dereferenced, otherwise there is no error
75+
76+
bool noReturnInScope = true;
77+
for (const Token *rt = scope->classStart; rt != scope->classEnd; rt = rt->next()) {
78+
if (rt->str() != "return") continue; // find all return statements
79+
if (inSameScope(rt, tok2)) {
80+
noReturnInScope = false;
8581
break;
8682
}
8783
}
84+
if (noReturnInScope) continue;
85+
86+
sideEffectInAssertError(tmp, f->name());
87+
break;
8888
}
8989
}
9090
tok = endTok;

0 commit comments

Comments
 (0)