Skip to content

Commit c3666a1

Browse files
committed
Fix for M0-1-4's testcase failures
1 parent 0f64260 commit c3666a1

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

cpp/autosar/src/rules/M0-1-3/UnusedLocalVariable.ql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,13 @@ where
5656
not isExcluded(v, DeadCodePackage::unusedLocalVariableQuery()) and
5757
// Local variable is never accessed
5858
not exists(v.getAnAccess()) and
59+
// Sometimes multiple objects representing the same entities are created in
60+
// the AST. Check if those are not accessed as well. Refer issue #658
61+
not exists(LocalScopeVariable another |
62+
another.getDefinitionLocation() = v.getDefinitionLocation() and
63+
another.hasName(v.getName()) and
64+
exists(another.getAnAccess()) and
65+
another != v
66+
) and
5967
getUseCountConservatively(v) = 0
6068
select v, "Local variable '" + v.getName() + "' in '" + v.getFunction().getName() + "' is not used."

cpp/common/src/codingstandards/cpp/deadcode/UnusedVariables.qll

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,7 @@ class PotentiallyUnusedLocalVariable extends LocalVariable {
5252
// exclude uninstantiated template members
5353
not this.isFromUninstantiatedTemplate(_) and
5454
// Do not report compiler generated variables
55-
not this.isCompilerGenerated() and
56-
not exists(LocalScopeVariable another |
57-
another.getDefinitionLocation() = this.getDefinitionLocation() and
58-
another.hasName(this.getName()) and
59-
exists(another.getAnAccess())
60-
)
55+
not this.isCompilerGenerated()
6156
}
6257
}
6358

0 commit comments

Comments
 (0)