Closed
Description
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
int main() {
constexpr int constexpr_unused = 1; // True Positives, these first three are indeed unused / dead code
static const int static_const_unused = 2;
int unused_variable = 3;
constexpr int constexpr_size = 7; // dead code detection <-- False Positive, it is used in array a
static const int static_const_size = 8; // True Negative,
// (static) const doesn't trigger dead code
int a[constexpr_size] = {}; // The remaining have no dead code issue either
int c[static_const_size] = {}; // they are used at the end
return a[0] + c[2];
}