Affected rules
Description
If the assignment is initializing a variable with the [[maybe_unused]] attribute, we should not report this.
The presence of [[maybe_unused]] disables other rules according to the MISRA spec, and we should follow that principle here as well. If a variable is [[maybe_unused]], that strongly indicates that there's some kind of conditional compilation that uses the variable value, and that the write is ok.
Note that [[maybe_unused]] should not disable all violations of the rule, only ones that would be fixed by adding any read to the variable.
Example
void example_function() {
[[maybe_unused]] int x = 0; // reported, but should not be.
[[maybe_unused]] int y = 1; // should still be reported
y = 2;
[[maybe_unused]] int z = 3;
f(z);
z = 4; // should still be reported.
}
Affected rules
RULE-0-1-1Description
If the assignment is initializing a variable with the
[[maybe_unused]]attribute, we should not report this.The presence of
[[maybe_unused]]disables other rules according to the MISRA spec, and we should follow that principle here as well. If a variable is[[maybe_unused]], that strongly indicates that there's some kind of conditional compilation that uses the variable value, and that the write is ok.Note that
[[maybe_unused]]should not disable all violations of the rule, only ones that would be fixed by adding any read to the variable.Example