MISRA C++:2023 Rule 6.7.1
Description
Rule Definition
Local variables shall not have static storage duration.
Rationale
Multiple threads or functions can access objects with static
storage duration simultaneously. Sharing access to local objects across functions can
lead to multiple functions reading or writing the same object, resulting in data races
and undefined behavior.
This rule does not apply to const
or constexpr
objects.
Polyspace Implementation
Polyspace® reports a violation of this rule if you declare a local object or a local
anonymous union using the static
keyword.
As an exception, Polyspace does not report violations of this rule if you declare local
const
and constexpr
objects using these
keywords.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Basic Concepts |
Category: Required |
Version History
Introduced in R2024b