Rule 0-1-6 Variables being given values that are never used. - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18) +--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19) +---- Forum: 6.0 Language independent issues (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=129) +---- Thread: Rule 0-1-6 Variables being given values that are never used. (/showthread.php?tid=1522) |
Rule 0-1-6 Variables being given values that are never used. - LordMordac - 17-01-2020 The actual rule is: Quote:A project shall not contain instances of non-volatile variables being given values that are never subsequently used.There has been a lot of discussion as to what that sentence actually means. One camp believes that this rule applies to DU dataflow anomalies only, and the other believes that it applies to DU and DD dataflow anomalies. For example the following code contains a DD dataflow anomaly, but not a DU dataflow anomaly. Is it a Rule 0-1-6 violation? Code: int32_t foobar (int32_t const value) This debate is influencing discussions on the merits of variable initialization. Re: Rule 0-1-6 Variables being given values that are never used. - misra cpp - 22-01-2020 The rule was intended to address DU anomalies only. Note that the rationale in the MISRA standard for this rule starts “Technically known as a DU dataflow anomaly…” Re: Rule 0-1-6 Variables being given values that are never used. - chgros - 24-01-2020 So, just to make sure, this is compliant according to this rule: Code: int i = 1; Re: Rule 0-1-6 Variables being given values that are never used. - misra cpp - 22-04-2020 This is a DD anomaly, not DU, so is compliant with 0-1-6. However it ought to be regarded as having dead-code, and be reported by 0-1-9. Unfortunately, the current wording of 0-1-9 which talks about 'removing statements' means that this isn't dead-code by 0-1-9's definition. We are looking at this for the next version |