Closed fjatWbyT closed 1 month ago
Add an additional case to the predicate isDeadStmt
in DeadCode.qll
. The approach in #660 can be reused to determine if the constant expression is used in an array size.
There could be value avoiding a bit of code duplication so that the M0-1-3 fix from that PR and this proposed fix for M0-1-9 share a predicate that returns the count.
As I am still learning CodeQL and writing my first queries, I have already been playing with the fix in c765f9375 and unit-testing it. I tried first using the pure / maybePure builtin predicates, but I didn’t manage to separate the constexpr and const cases only with them.
I think your fix sounds reasonable 👍
Thank you 😊 I have applied it in #690.
Affected rules
M0-1-9
(dead code)Description
Integer constant expression used for the size in an array declaration produces dead-code false positive. In other words, the e.g.
constexpr int
is not dead code because it is used to define the array size. This is contrast with when the size is (static) const, which does not produce the alert.Example