Improved const correctness of local variables. There are no functional changes intended. (#1392)
This commit is contained in:
parent
6ceab1f245
commit
d08b39c915
|
@ -1987,7 +1987,7 @@ void CheckStl::useStlAlgorithm()
|
|||
const Token *memberAccessTok = singleMemberCallInScope(bodyTok, loopVar->varId(), useLoopVarInMemCall);
|
||||
if (memberAccessTok) {
|
||||
const Token *memberCallTok = memberAccessTok->astOperand2();
|
||||
unsigned int contVarId = memberAccessTok->astOperand1()->varId();
|
||||
const unsigned int contVarId = memberAccessTok->astOperand1()->varId();
|
||||
if (contVarId == loopVar->varId())
|
||||
continue;
|
||||
if (memberCallTok->str() == "push_back" ||
|
||||
|
@ -2022,7 +2022,7 @@ void CheckStl::useStlAlgorithm()
|
|||
// Check for single assign
|
||||
assignTok = singleAssignInScope(condBodyTok, loopVar->varId(), useLoopVarInAssign);
|
||||
if (assignTok) {
|
||||
unsigned int assignVarId = assignTok->astOperand1()->varId();
|
||||
const unsigned int assignVarId = assignTok->astOperand1()->varId();
|
||||
std::string algo;
|
||||
if (assignVarId == loopVar->varId()) {
|
||||
if (useLoopVarInAssign)
|
||||
|
@ -2045,7 +2045,7 @@ void CheckStl::useStlAlgorithm()
|
|||
memberAccessTok = singleMemberCallInScope(condBodyTok, loopVar->varId(), useLoopVarInMemCall);
|
||||
if (memberAccessTok) {
|
||||
const Token *memberCallTok = memberAccessTok->astOperand2();
|
||||
unsigned int contVarId = memberAccessTok->astOperand1()->varId();
|
||||
const unsigned int contVarId = memberAccessTok->astOperand1()->varId();
|
||||
if (contVarId == loopVar->varId())
|
||||
continue;
|
||||
if (memberCallTok->str() == "push_back" ||
|
||||
|
|
|
@ -927,7 +927,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||
tok = tok->next();
|
||||
}
|
||||
|
||||
Variables::VariableUsage *var = variables.find(varid);
|
||||
const Variables::VariableUsage *const var = variables.find(varid);
|
||||
if (var && !var->_allocateMemory) {
|
||||
variables.readAll(varid, tok);
|
||||
}
|
||||
|
@ -998,13 +998,13 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||
variables.use(varid1, tok);
|
||||
|
||||
if (dereference) {
|
||||
Variables::VariableUsage *var = variables.find(varid1);
|
||||
const Variables::VariableUsage *const var = variables.find(varid1);
|
||||
if (var && var->mType == Variables::array)
|
||||
variables.write(varid1, tok);
|
||||
variables.writeAliases(varid1, tok);
|
||||
variables.read(varid1, tok);
|
||||
} else {
|
||||
Variables::VariableUsage *var = variables.find(varid1);
|
||||
const Variables::VariableUsage *const var = variables.find(varid1);
|
||||
if (var && (inwhile || start->strAt(-1) == ",")) {
|
||||
variables.use(varid1, tok);
|
||||
} else if (var && var->mType == Variables::reference) {
|
||||
|
@ -1051,7 +1051,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||
}
|
||||
}
|
||||
|
||||
Variables::VariableUsage *var2 = variables.find(tok->varId());
|
||||
const Variables::VariableUsage * const var2 = variables.find(tok->varId());
|
||||
if (var2) {
|
||||
if (var2->mType == Variables::reference) {
|
||||
variables.writeAliases(tok->varId(), tok);
|
||||
|
@ -1069,7 +1069,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||
// checked for chained assignments
|
||||
if (tok != start && equal && equal->str() == "=") {
|
||||
const unsigned int varId = tok->varId();
|
||||
Variables::VariableUsage *var = variables.find(varId);
|
||||
const Variables::VariableUsage * const var = variables.find(varId);
|
||||
|
||||
if (var && var->mType != Variables::reference) {
|
||||
variables.read(varId,tok);
|
||||
|
|
|
@ -522,7 +522,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
|||
// nested class or friend function?
|
||||
else {
|
||||
/** @todo check entire qualification for match */
|
||||
Scope * nested = scope->findInNestedListRecursive(tok->strAt(-2));
|
||||
const Scope * const nested = scope->findInNestedListRecursive(tok->strAt(-2));
|
||||
|
||||
if (nested)
|
||||
addClassFunction(&scope, &tok, argStart);
|
||||
|
@ -579,7 +579,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
|
|||
|
||||
// regular function
|
||||
else {
|
||||
Function* function = addGlobalFunction(scope, tok, argStart, funcStart);
|
||||
const Function* const function = addGlobalFunction(scope, tok, argStart, funcStart);
|
||||
|
||||
if (!function)
|
||||
mTokenizer->syntaxError(tok);
|
||||
|
@ -679,7 +679,7 @@ void SymbolDatabase::createSymbolDatabaseClassInfo()
|
|||
// only find if not already found
|
||||
if (i->scope == nullptr) {
|
||||
// check scope for match
|
||||
Scope *scope = findScope(i->start->tokAt(2), &(*it));
|
||||
const Scope * const scope = findScope(i->start->tokAt(2), &(*it));
|
||||
if (scope) {
|
||||
// set found scope
|
||||
i->scope = scope;
|
||||
|
|
|
@ -550,7 +550,7 @@ std::list<TemplateSimplifier::TokenAndName> TemplateSimplifier::getTemplateDecla
|
|||
!Token::Match(tok->tokAt(3), "%name%|.|,|=|>"))
|
||||
syntaxError(tok->next());
|
||||
codeWithTemplates = true;
|
||||
Token *parmEnd = tok->next()->findClosingBracket();
|
||||
const Token * const parmEnd = tok->next()->findClosingBracket();
|
||||
for (const Token *tok2 = parmEnd; tok2; tok2 = tok2->next()) {
|
||||
if (tok2->str() == "(")
|
||||
tok2 = tok2->link();
|
||||
|
@ -848,7 +848,7 @@ void TemplateSimplifier::simplifyTemplateAliases()
|
|||
}
|
||||
tok2 = aliasUsage.token->next(); // the '<'
|
||||
const Token * const endToken1 = templateAlias.token->next()->findClosingBracket();
|
||||
Token * const endToken2 = TokenList::copyTokens(tok2, templateAlias.token->tokAt(2), endToken1->previous(), false);
|
||||
const Token * const endToken2 = TokenList::copyTokens(tok2, templateAlias.token->tokAt(2), endToken1->previous(), false);
|
||||
for (const Token *tok1 = templateAlias.token->next(); tok2 != endToken2; tok1 = tok1->next(), tok2 = tok2->next()) {
|
||||
if (!tok2->isName())
|
||||
continue;
|
||||
|
@ -1758,7 +1758,7 @@ void TemplateSimplifier::replaceTemplateUsage(Token * const instantiationToken,
|
|||
// matching template usage => replace tokens..
|
||||
// Foo < int > => Foo<int>
|
||||
if (tok2->str() == ">" && typeCountInInstantiation == typesUsedInTemplateInstantiation.size()) {
|
||||
Token * const nameTok1 = nameTok;
|
||||
const Token * const nameTok1 = nameTok;
|
||||
while (Token::Match(nameTok->tokAt(-2), "%name% :: %name%"))
|
||||
nameTok = nameTok->tokAt(-2);
|
||||
nameTok->str(newName);
|
||||
|
|
|
@ -4286,7 +4286,7 @@ void Tokenizer::removeRedundantAssignment()
|
|||
if (tok->str() == "{")
|
||||
tok = tok->link();
|
||||
|
||||
Token * start = const_cast<Token *>(startOfExecutableScope(tok));
|
||||
const Token * const start = const_cast<Token *>(startOfExecutableScope(tok));
|
||||
if (start) {
|
||||
tok = start->previous();
|
||||
// parse in this function..
|
||||
|
@ -8666,8 +8666,8 @@ void Tokenizer::simplifyFuncInWhile()
|
|||
continue;
|
||||
|
||||
Token *func = tok->tokAt(2);
|
||||
Token *var = tok->tokAt(4);
|
||||
Token *end = tok->next()->link()->next()->link();
|
||||
const Token * const var = tok->tokAt(4);
|
||||
Token * const end = tok->next()->link()->next()->link();
|
||||
|
||||
const unsigned int varid = ++mVarId; // Create new variable
|
||||
const std::string varname("cppcheck:r" + MathLib::toString(++count));
|
||||
|
@ -8745,7 +8745,7 @@ void Tokenizer::simplifyStructDecl()
|
|||
Token *start = tok;
|
||||
while (Token::Match(start->previous(), "%type%"))
|
||||
start = start->previous();
|
||||
Token *type = tok->next();
|
||||
const Token * const type = tok->next();
|
||||
Token *next = tok->tokAt(2);
|
||||
|
||||
while (next && next->str() != "{")
|
||||
|
@ -9381,7 +9381,7 @@ void Tokenizer::simplifyBitfields()
|
|||
Token * tok1 = last;
|
||||
tok1->str(";");
|
||||
|
||||
Token *tok2 = tok->next();
|
||||
const Token *const tok2 = tok->next();
|
||||
tok1->insertToken(tok2->str());
|
||||
tok1 = tok1->next();
|
||||
tok1->isSigned(tok2->isSigned());
|
||||
|
@ -9950,7 +9950,7 @@ void Tokenizer::simplifyReturnStrncat()
|
|||
tok2->insertToken(";");
|
||||
|
||||
//the last token of the first argument before ','
|
||||
Token *end = tok->next()->nextArgument()->tokAt(-2);
|
||||
const Token * const end = tok->next()->nextArgument()->tokAt(-2);
|
||||
|
||||
//all the first argument is copied
|
||||
TokenList::copyTokens(tok2, tok->next(), end);
|
||||
|
@ -10057,7 +10057,7 @@ void Tokenizer::simplifyMathExpressions()
|
|||
const std::string& leftExponent = tok2->strAt(2);
|
||||
if (!isTwoNumber(leftExponent))
|
||||
continue; // left exponent is not 2
|
||||
Token * const tok3 = tok2->tokAt(8);
|
||||
const Token * const tok3 = tok2->tokAt(8);
|
||||
Token * const tok4 = tok3->link();
|
||||
if (!Token::Match(tok4, ") , %num% )"))
|
||||
continue;
|
||||
|
@ -10075,7 +10075,7 @@ void Tokenizer::simplifyMathExpressions()
|
|||
const std::string& leftExponent = tok2->strAt(2);
|
||||
if (!isTwoNumber(leftExponent))
|
||||
continue; // left exponent is not 2
|
||||
Token * const tok3 = tok2->tokAt(8);
|
||||
const Token * const tok3 = tok2->tokAt(8);
|
||||
Token * const tok4 = tok3->link();
|
||||
if (!Token::Match(tok4, ") , %num% )"))
|
||||
continue;
|
||||
|
@ -10093,7 +10093,7 @@ void Tokenizer::simplifyMathExpressions()
|
|||
const std::string& leftExponent = tok2->strAt(2);
|
||||
if (!isTwoNumber(leftExponent))
|
||||
continue; // left exponent is not 2
|
||||
Token * const tok3 = tok2->tokAt(8);
|
||||
const Token * const tok3 = tok2->tokAt(8);
|
||||
Token * const tok4 = tok3->link();
|
||||
if (!Token::Match(tok4, ") , %num% )"))
|
||||
continue;
|
||||
|
@ -10111,7 +10111,7 @@ void Tokenizer::simplifyMathExpressions()
|
|||
const std::string& leftExponent = tok2->strAt(2);
|
||||
if (!isTwoNumber(leftExponent))
|
||||
continue; // left exponent is not 2
|
||||
Token * const tok3 = tok2->tokAt(8);
|
||||
const Token * const tok3 = tok2->tokAt(8);
|
||||
Token * const tok4 = tok3->link();
|
||||
if (!Token::Match(tok4, ") , %num% )"))
|
||||
continue;
|
||||
|
|
|
@ -695,7 +695,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
|
|||
}
|
||||
}
|
||||
|
||||
Token* tok2 = tok;
|
||||
const Token* const tok2 = tok;
|
||||
if (tok->strAt(1) != "]")
|
||||
compileBinOp(tok, state, compileExpression);
|
||||
else
|
||||
|
@ -1152,7 +1152,7 @@ static Token * createAstAtToken(Token *tok, bool cpp)
|
|||
Token * const tok1 = tok;
|
||||
AST_state state(cpp);
|
||||
compileExpression(tok, state);
|
||||
Token * const endToken = tok;
|
||||
const Token * const endToken = tok;
|
||||
if (endToken == tok1 || !endToken)
|
||||
return tok1;
|
||||
|
||||
|
|
|
@ -1735,7 +1735,7 @@ static bool valueFlowForward(Token * const startToken,
|
|||
}
|
||||
if (truevalues.size() != values.size() || condAlwaysTrue) {
|
||||
// '{'
|
||||
Token * const startToken1 = tok2->linkAt(1)->next();
|
||||
const Token * const startToken1 = tok2->linkAt(1)->next();
|
||||
|
||||
bool vfresult = valueFlowForward(startToken1->next(),
|
||||
startToken1->link(),
|
||||
|
@ -1763,7 +1763,7 @@ static bool valueFlowForward(Token * const startToken,
|
|||
}
|
||||
|
||||
if (Token::simpleMatch(tok2, "} else {")) {
|
||||
Token * const startTokenElse = tok2->tokAt(2);
|
||||
const Token * const startTokenElse = tok2->tokAt(2);
|
||||
|
||||
vfresult = valueFlowForward(startTokenElse->next(),
|
||||
startTokenElse->link(),
|
||||
|
@ -2219,7 +2219,7 @@ static bool isStdMoveOrStdForwarded(Token * tok, ValueFlow::Value::MoveKind * mo
|
|||
variableToken = tok->tokAt(4);
|
||||
kind = ValueFlow::Value::MovedVariable;
|
||||
} else if (Token::simpleMatch(tok, "std :: forward <")) {
|
||||
Token * leftAngle = tok->tokAt(3);
|
||||
const Token * const leftAngle = tok->tokAt(3);
|
||||
Token * rightAngle = leftAngle->link();
|
||||
if (Token::Match(rightAngle, "> ( %var% )")) {
|
||||
variableToken = rightAngle->tokAt(2);
|
||||
|
@ -2602,7 +2602,7 @@ static void valueFlowAfterCondition(TokenList *tokenlist, SymbolDatabase* symbol
|
|||
bool bail = false;
|
||||
|
||||
for (int i=0; i<2; i++) {
|
||||
Token * startToken = startTokens[i];
|
||||
const Token * const startToken = startTokens[i];
|
||||
if (!startToken)
|
||||
continue;
|
||||
std::list<ValueFlow::Value> & values = (i==0 ? true_values : false_values);
|
||||
|
|
Loading…
Reference in New Issue