@@ -85,9 +85,10 @@ Expr getLoopStepOfForStmt(ForStmt forLoop) {
8585predicate loopVariableAssignedToNonConstPointerOrReferenceType (
8686ForStmt forLoop , VariableAccess loopVariableAccessInCondition
8787) {
88- exists ( Expr assignmentRhs , DerivedType targetType |
88+ exists ( Expr assignmentRhs , Type targetType , DerivedType strippedType |
8989isAssignment ( assignmentRhs , targetType , _) and
90- not targetType .getBaseType ( ) .isConst ( ) and
90+ strippedType = targetType .stripTopLevelSpecifiers ( ) and
91+ not strippedType .getBaseType ( ) .isConst ( ) and
9192(
9293targetType instanceof PointerType or
9394targetType instanceof ReferenceType
@@ -105,9 +106,14 @@ predicate loopVariableAssignedToNonConstPointerOrReferenceType(
105106)
106107}
107108
108- /*
109- * An adapted part of `BuiltinTypeRules::MisraCpp23BuiltInTypes::isPreConversionAssignment`
110- * that is only relevant to an argument passed to a parameter, seen as an assignment.
109+ /**
110+ * Holds if the given variable access has another variable access with the same target
111+ * variable that is passed as reference to a non-const reference parameter of a function,
112+ * constituting a `T` -> `&T` conversion.
113+ *
114+ * This is an adapted part of
115+ * `BuiltinTypeRules::MisraCpp23BuiltInTypes::isPreConversionAssignment` that is only
116+ * relevant to an argument passed to a parameter, seen as an assignment.
111117 *
112118 * This predicate adds two constraints to the target type, as compared to the original
113119 * portion of the predicate:
@@ -117,20 +123,15 @@ predicate loopVariableAssignedToNonConstPointerOrReferenceType(
117123 *
118124 * Also, this predicate requires that the call is the body of the given for-loop.
119125 */
120-
121- /**
122- * Holds if the given variable access has another variable access with the same target
123- * variable that is passed as reference to a non-const reference parameter of a function,
124- * constituting a `T` -> `&T` conversion.
125- */
126126predicate loopVariablePassedAsArgumentToNonConstReferenceParameter (
127127ForStmt forLoop , VariableAccess loopVariableAccessInCondition
128128) {
129- exists ( ReferenceType targetType |
129+ exists ( Type targetType , ReferenceType strippedReferenceType |
130130exists ( Call call , int i |
131131call .getArgument ( i ) = loopVariableAccessInCondition .getTarget ( ) .getAnAccess ( ) and
132132call .getEnclosingStmt ( ) .getParent * ( ) = forLoop .getStmt ( ) and
133- not targetType .getBaseType ( ) .isConst ( )
133+ strippedReferenceType = targetType .stripTopLevelSpecifiers ( ) and
134+ not strippedReferenceType .getBaseType ( ) .isConst ( )
134135|
135136/* A regular function call */
136137targetType = call .getTarget ( ) .getParameter ( i ) .getType ( )