![]() |
|
Rule 6.7.1 and local declarations with external linkage - 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++:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=188) +---- Forum: 4.6 Basic concepts (https://forum.misra.org.uk/forumdisplay.php?fid=192) +---- Thread: Rule 6.7.1 and local declarations with external linkage (/showthread.php?tid=1763) |
Rule 6.7.1 and local declarations with external linkage - karos - 27-01-2026 Is this rule intended to apply to variable declarations of external linkage? For example: Code: int main()'var' is declared at block scope, refers to an object of static storage duration and is not const-qualified. Hence, it appears to be non-compliant with this rule. However, my feeling is that it does not really fit the rationale of the rule as it does not add persistent state to the function (this declaration cannot be a definition, so some definition of var must exist outside of main). One could argue that var is effectively not local to the function containing the declaration. Can you please clarify? PS: I'm aware that such code does not comply with other rules as well (e.g. 6.7.2). RE: Rule 6.7.1 and local declarations with external linkage - misra cpp - 30-01-2026 We agree with your analysis - the rule applies to this declaration and is non-compliant (and is also non-compliant with 6.7.2). This wasn't our intension. We are looking at a revision along the lines of 'all local declarations should have automatic or thread_local storage duration'. |