Skip to content

Commit d36b2c3

Browse files
Fix compile error from function being moved into module
1 parent 91b613b commit d36b2c3

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,27 @@ predicate isDefined(MemberFunction mf) {
5353
)
5454
}
5555

56+
/** Gets the constant value of a constexpr/const variable. */
57+
string getConstExprValue(Variable v) {
58+
result = v.getInitializer().getExpr().getValue() and
59+
(v.isConst() or v.isConstexpr())
60+
}
61+
62+
/**
63+
* Counts uses of `Variable` v in a local array of size `n`.
64+
*
65+
* For non `LocalVariable`s, this will return as zero. This is intentional.
66+
*/
67+
int countUsesInLocalArraySize(Variable v) {
68+
result =
69+
count(ArrayType at, LocalVariable arrayVariable |
70+
arrayVariable.getType().resolveTypedefs() = at and
71+
//v.(SecondPassUnused::UnusedLocalVariable).getFunction() = arrayVariable.getFunction() and
72+
v.(LocalVariable).getFunction() = arrayVariable.getFunction() and
73+
at.getArraySize().toString() = getConstExprValue(v)
74+
)
75+
}
76+
5677
/** A `Class` where all non compiler generated member functions are defined in the current database. */
5778
class FullyDefinedClass extends Class {
5879
FullyDefinedClass() {
@@ -211,24 +232,6 @@ module ThirdPassUnused {
211232
)
212233
}
213234

214-
/** Gets the constant value of a constexpr/const variable. */
215-
string getConstExprValue(Variable v) {
216-
result = v.getInitializer().getExpr().getValue() and
217-
(v.isConst() or v.isConstexpr())
218-
}
219-
220-
/**
221-
* Counts uses of `Variable` v in a local array of size `n`
222-
*/
223-
int countUsesInLocalArraySize(Variable v) {
224-
result =
225-
count(ArrayType at, LocalVariable arrayVariable |
226-
arrayVariable.getType().resolveTypedefs() = at and
227-
v.(SecondPassUnused::UnusedLocalVariable).getFunction() = arrayVariable.getFunction() and
228-
at.getArraySize().toString() = getConstExprValue(v)
229-
)
230-
}
231-
232235
// Collect constant values that we should use to exclude otherwise unused constexpr variables.
233236
//
234237
// For constexpr variables used as template arguments or in static_asserts, we don't see accesses

0 commit comments

Comments
 (0)