Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7d5f08b

Browse files
committed
Count in typedefs and cv-qualifiers
We are interested if the underlying *data* can bemutated, not the pointer itself. Also, the surfacetype may be a typedef, so resolve that as well.
1 parentf0b53e2 commit7d5f08b

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

‎cpp/misra/src/rules/RULE-9-5-1/LegacyForStatementsShouldBeSimple.ql‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ Expr getLoopStepOfForStmt(ForStmt forLoop) {
8585
predicateloopVariableAssignedToNonConstPointerOrReferenceType(
8686
ForStmtforLoop,VariableAccessloopVariableAccessInCondition
8787
){
88-
exists(ExprassignmentRhs,DerivedTypetargetType|
88+
exists(ExprassignmentRhs,TypetargetType,DerivedTypestrippedType|
8989
isAssignment(assignmentRhs,targetType, _)and
90-
nottargetType.getBaseType().isConst()and
90+
strippedType=targetType.stripTopLevelSpecifiers()and
91+
notstrippedType.getBaseType().isConst()and
9192
(
9293
targetTypeinstanceofPointerTypeor
9394
targetTypeinstanceofReferenceType
@@ -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-
*/
126126
predicateloopVariablePassedAsArgumentToNonConstReferenceParameter(
127127
ForStmtforLoop,VariableAccessloopVariableAccessInCondition
128128
){
129-
exists(ReferenceTypetargetType|
129+
exists(TypetargetType,ReferenceTypestrippedReferenceType|
130130
exists(Callcall,inti|
131131
call.getArgument(i)=loopVariableAccessInCondition.getTarget().getAnAccess()and
132132
call.getEnclosingStmt().getParent*()=forLoop.getStmt()and
133-
nottargetType.getBaseType().isConst()
133+
strippedReferenceType=targetType.stripTopLevelSpecifiers()and
134+
notstrippedReferenceType.getBaseType().isConst()
134135
|
135136
/* A regular function call */
136137
targetType=call.getTarget().getParameter(i).getType()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp