@@ -12,35 +12,35 @@ abstract class IdentifierHiddenSharedQuery extends Query { }
12
12
Query getQuery ( ) { result instanceof IdentifierHiddenSharedQuery }
13
13
14
14
/**
15
- * There is a lambda that contains a declaration
16
- * that hides something that is captured
17
- * and the lambda exists in the function where this lamda is enclosed
15
+ * Holds if declaration `innerDecl`, declared in a lambda, hides a declaration `outerDecl` captured by the lambda.
18
16
*/
19
- predicate hiddenInLambda ( UserDeclaration v2 , UserDeclaration v1 ) {
17
+ predicate hiddenInLambda ( UserVariable outerDecl , UserVariable innerDecl ) {
20
18
exists ( Scope s , Closure le |
21
- s .getADeclaration ( ) = v2 and
19
+ //innerDecl declared inside of the lambda
20
+ s .getADeclaration ( ) = innerDecl and
22
21
s .getAnAncestor ( ) = le and
23
- le .getEnclosingFunction ( ) .getBasicBlock ( ) .( Scope ) = v1 .getParentScope ( ) and
24
- exists ( LambdaCapture cap , Variable v |
25
- v .getAnAccess ( ) = cap .getInitializer ( ) .( VariableAccess ) and
26
- v = v1 and
22
+ le .getEnclosingFunction ( ) .getBasicBlock ( ) .( Scope ) = outerDecl .getParentScope ( ) and
23
+ exists ( LambdaCapture cap |
24
+ outerDecl .getAnAccess ( ) = cap .getInitializer ( ) .( VariableAccess ) and
27
25
le .getLambdaExpression ( ) .getACapture ( ) = cap
28
26
) and
29
- v2 .getName ( ) = v1 .getName ( )
27
+ innerDecl .getName ( ) = outerDecl .getName ( )
30
28
)
31
29
}
32
30
33
- query predicate problems ( UserDeclaration v2 , string message , UserDeclaration v1 , string varName ) {
34
- not isExcluded ( v1 , getQuery ( ) ) and
35
- not isExcluded ( v2 , getQuery ( ) ) and
31
+ query predicate problems (
32
+ UserDeclaration innerDecl , string message , UserDeclaration outerDecl , string varName
33
+ ) {
34
+ not isExcluded ( outerDecl , getQuery ( ) ) and
35
+ not isExcluded ( innerDecl , getQuery ( ) ) and
36
36
//ignore template variables for this rule
37
- not v1 instanceof TemplateVariable and
38
- not v2 instanceof TemplateVariable and
39
- //ignore types for this rule
40
- not v2 instanceof Type and
41
- not v1 instanceof Type and
42
- ( hidesStrict ( v1 , v2 ) or hiddenInLambda ( v2 , v1 ) ) and
43
- not excludedViaNestedNamespaces ( v2 , v1 ) and
44
- varName = v1 .getName ( ) and
37
+ not outerDecl instanceof TemplateVariable and
38
+ not innerDecl instanceof TemplateVariable and
39
+ //ignore types for this rule as the Misra C/C++ 23 version of this rule (rule 6.4.1 and 6.4.2) focuses solely on variables and functions
40
+ not innerDecl instanceof Type and
41
+ not outerDecl instanceof Type and
42
+ ( hidesStrict ( outerDecl , innerDecl ) or hiddenInLambda ( outerDecl , innerDecl ) ) and
43
+ not excludedViaNestedNamespaces ( outerDecl , innerDecl ) and
44
+ varName = outerDecl .getName ( ) and
45
45
message = "Declaration is hiding declaration $@."
46
46
}
0 commit comments