MISRA C++:2023 Rule 6.5.2
Description
Rule Definition
Internal linkage should be specified appropriately.
Rationale
To comply with this rule:
Specify the internal linkage of an identifier unambiguously by declaring the identifier in an anonymous namespace.
Do not:
Use the
static
keyword to specify internal linkage. Thestatic
keyword has other uses and using it to specify internal linkage can be ambiguous.Declare or redeclare identifiers declared in an anonymous namespace with the
extern
keyword. Identifiers declared in an anonymous namespace have internal linkage. If you redeclare them using theextern
keyword, the compiler ignores the keyword the code can be confusing to read.
Polyspace Implementation
Polyspace® reports a violation of this rule if any of these are true:
You declare an identifier in an anonymous namespace by using either the
static
orextern
keywords.You declare a namespace-scope
const
,constexpr
, orinline
variable outside an anonymous namespace. Namespace-scopeconst
,constexpr
, orinline
variables have internal linkage. To comply with this rule, declare such variables in anonymous namespaces.
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: Advisory |
Version History
Introduced in R2024b