MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / checkVariableAssignment

Method checkVariableAssignment

lib/checkassert.cpp:145–173  ·  view source on GitHub ↗

checks if side effects happen on the variable prior to tmp

Source from the content-addressed store, hash-verified

143
144// checks if side effects happen on the variable prior to tmp
145void CheckAssertImpl::checkVariableAssignment(const Token* assignTok, const Scope *assertionScope)
146{
147 if (!assignTok->isAssignmentOp() && assignTok->tokType() != Token::eIncDecOp)
148 return;
149
150 if (!assignTok->astOperand1())
151 return;
152 const Variable* var = assignTok->astOperand1()->variable();
153 if (!var)
154 return;
155
156 // Variable declared in inner scope in assert => don't warn
157 if (assertionScope != var->scope()) {
158 const Scope *s = var->scope();
159 while (s && s != assertionScope)
160 s = s->nestedIn;
161 if (s == assertionScope)
162 return;
163 }
164
165 // assignment
166 if (assignTok->isAssignmentOp() || assignTok->tokType() == Token::eIncDecOp) {
167 if (var->isConst()) {
168 return;
169 }
170 assignmentInAssertError(assignTok, var->name());
171 }
172 // TODO: function calls on var
173}
174
175bool CheckAssertImpl::inSameScope(const Token* returnTok, const Token* assignTok)
176{

Callers

nothing calls this directly

Calls 6

isAssignmentOpMethod · 0.80
astOperand1Method · 0.80
variableMethod · 0.80
scopeMethod · 0.80
isConstMethod · 0.80
nameMethod · 0.45

Tested by

no test coverage detected