Skip to content

Commit 3b548fe

Browse files
committed
M6-5-2: Expand definition of modification
Identify calls to non-const functions as "modifying" the local variable.
1 parent 7221dc4 commit 3b548fe

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

cpp/common/src/codingstandards/cpp/Loops.qll

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,19 @@ predicate isInvalidForLoopIncrementation(ForStmt forLoop, Variable v, VariableAc
123123
v = getAnIterationVariable(forLoop) and
124124
modification = v.getAnAccess() and
125125
modification = forLoop.getUpdate().getAChild*() and
126-
modification.isModified() and
126+
// Is modified
127+
(
128+
// Variable directly modified
129+
modification.isModified()
130+
or
131+
// Has a call to a member function on the variable, where the target is non-const,
132+
// i.e. can modify the state of the object
133+
exists(Call c |
134+
c.getQualifier() = modification and
135+
not c.getTarget() instanceof ConstMemberFunction
136+
)
137+
) and
138+
// And not by a call to a crement operator
127139
not exists(CrementOperation cop | cop.getOperand() = modification) and
128140
not exists(Call c |
129141
c.getQualifier() = modification and c.getTarget() instanceof UserCrementOperator

0 commit comments

Comments
 (0)