MISRA C++:2023 Rule 6.5.2
Description
Rule Definition
Internal linkage should be specified appropriately. 1
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
statickeyword to specify internal linkage. Thestatickeyword has other uses and using it to specify internal linkage can be ambiguous.Declare or redeclare identifiers declared in an anonymous namespace with the
externkeyword. Identifiers declared in an anonymous namespace have internal linkage. If you redeclare them using theexternkeyword, 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
staticorexternkeywords.You declare an identifier in the global namespace using the
statickeyword.
This rule does not apply to const or
constexpr identifiers.
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
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.