Skip to content

Commit a3916c5

Browse files
committed
Refactor loop, use continue
1 parent da26ef0 commit a3916c5

1 file changed

Lines changed: 40 additions & 39 deletions

File tree

lib/checkclass.cpp

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,51 +1304,52 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
13041304

13051305
for (; tok && tok != last; tok = tok->next()) {
13061306
// check for return of reference to this
1307-
if (tok->str() == "return") {
1308-
foundReturn = true;
1309-
std::string cast("( " + scope->className + " & )");
1310-
if (Token::simpleMatch(tok->next(), cast.c_str()))
1311-
tok = tok->tokAt(4);
1312-
1313-
// check if a function is called
1314-
if (tok->strAt(2) == "(" &&
1315-
tok->linkAt(2)->next()->str() == ";") {
1316-
std::list<Function>::const_iterator it;
1317-
1318-
// check if it is a member function
1319-
for (it = scope->functionList.begin(); it != scope->functionList.end(); ++it) {
1320-
// check for a regular function with the same name and a body
1321-
if (it->type == Function::eFunction && it->hasBody() &&
1322-
it->token->str() == tok->next()->str()) {
1323-
// check for the proper return type
1324-
if (it->tokenDef->previous()->str() == "&" &&
1325-
it->tokenDef->strAt(-2) == scope->className) {
1326-
// make sure it's not a const function
1327-
if (!it->isConst()) {
1328-
/** @todo make sure argument types match */
1329-
// avoid endless recursions
1330-
if (analyzedFunctions.find(&*it) == analyzedFunctions.end()) {
1331-
analyzedFunctions.insert(&*it);
1332-
checkReturnPtrThis(scope, &*it, it->arg->link()->next(), it->arg->link()->next()->link(),
1333-
analyzedFunctions);
1334-
}
1335-
// just bail for now
1336-
else
1337-
return;
1307+
if (tok->str() != "return")
1308+
continue;
1309+
1310+
foundReturn = true;
1311+
std::string cast("( " + scope->className + " & )");
1312+
if (Token::simpleMatch(tok->next(), cast.c_str()))
1313+
tok = tok->tokAt(4);
1314+
1315+
// check if a function is called
1316+
if (tok->strAt(2) == "(" &&
1317+
tok->linkAt(2)->next()->str() == ";") {
1318+
std::list<Function>::const_iterator it;
1319+
1320+
// check if it is a member function
1321+
for (it = scope->functionList.begin(); it != scope->functionList.end(); ++it) {
1322+
// check for a regular function with the same name and a body
1323+
if (it->type == Function::eFunction && it->hasBody() &&
1324+
it->token->str() == tok->next()->str()) {
1325+
// check for the proper return type
1326+
if (it->tokenDef->previous()->str() == "&" &&
1327+
it->tokenDef->strAt(-2) == scope->className) {
1328+
// make sure it's not a const function
1329+
if (!it->isConst()) {
1330+
/** @todo make sure argument types match */
1331+
// avoid endless recursions
1332+
if (analyzedFunctions.find(&*it) == analyzedFunctions.end()) {
1333+
analyzedFunctions.insert(&*it);
1334+
checkReturnPtrThis(scope, &*it, it->arg->link()->next(), it->arg->link()->next()->link(),
1335+
analyzedFunctions);
13381336
}
1337+
// just bail for now
1338+
else
1339+
return;
13391340
}
13401341
}
13411342
}
13421343
}
1343-
1344-
// check if *this is returned
1345-
else if (!(Token::Match(tok->next(), "(| * this ;|=") ||
1346-
Token::simpleMatch(tok->next(), "operator= (") ||
1347-
Token::simpleMatch(tok->next(), "this . operator= (") ||
1348-
(Token::Match(tok->next(), "%type% :: operator= (") &&
1349-
tok->next()->str() == scope->className)))
1350-
operatorEqRetRefThisError(func->token);
13511344
}
1345+
1346+
// check if *this is returned
1347+
else if (!(Token::Match(tok->next(), "(| * this ;|=") ||
1348+
Token::simpleMatch(tok->next(), "operator= (") ||
1349+
Token::simpleMatch(tok->next(), "this . operator= (") ||
1350+
(Token::Match(tok->next(), "%type% :: operator= (") &&
1351+
tok->next()->str() == scope->className)))
1352+
operatorEqRetRefThisError(func->token);
13521353
}
13531354
if (foundReturn) {
13541355
return;

0 commit comments

Comments
 (0)