Skip to content

Commit f6afab6

Browse files
committed
M14-6-1: Ensure local scope variables are ignored
Access of a local scope variable shadowing a dependent base member is not a case with confusing behaviour - the local scope variable would be expected to be the target.
1 parent c308956 commit f6afab6

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

cpp/autosar/src/rules/M14-6-1/NameInDependentBase.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ private VariableAccess helper_memberaccess(
9292
not target.getDeclaringType() = dependentBaseType and
9393
result = target.getAnAccess() and
9494
result.getEnclosingFunction() = t.getAMemberFunction() and
95-
name = target.getName()
95+
name = target.getName() and
96+
// The target is not a local variable, which isn't subject to confusion
97+
not target instanceof LocalScopeVariable
9698
}
9799

98100
/**

cpp/autosar/src/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThis.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ where
3131
fn = getConfusingFunctionCall(c, targetName, actualTarget, dependentTypeMemberWithSameName) and
3232
not exists(Expr e | e = fn.(FunctionCall).getQualifier())
3333
or
34-
not fn.(VariableAccess).getTarget() instanceof Parameter and
3534
fn =
3635
getConfusingMemberVariableAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName) and
3736
not exists(Expr e | e = fn.(VariableAccess).getQualifier())

cpp/autosar/test/rules/M14-6-1/test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,21 @@ template <typename T> class A : B<T> {
2929
typename B<T>::TYPE t2 = 0; // COMPLIANT
3030
g1(); // COMPLIANT, identifier not found in B
3131
}
32+
void m3(int m) {
33+
m = 0; // COMPLIANT, hides member
34+
}
35+
void m4() {
36+
int m = 0;
37+
m = 0; // COMPLIANT, hides member
38+
}
3239
};
3340

3441
void f() {
3542
A<int> a;
3643
a.m1();
3744
a.m2();
45+
a.m3(1);
46+
a.m4();
3847
}
3948

4049
class D {

0 commit comments

Comments
 (0)