MISRA C++:2023 Rule 6.2.3
Description
Rule Definition
The source code used to implement an entity shall appear only once 1
Rationale
This rule enforces the one-definition principle, which mandates:
Noninline entities shall be defined only once in a program across all translation units.
Inline entities shall be defined only once in a translation unit. The definitions of such entities in different translation units must be identical.
Violating the one-definition principle results in unintended implicit declarations, which leads to unexpected behavior.
Polyspace Implementation
Polyspace® reports a violation of this rule if any of these conditions are true:
You declare an
extern
object in multiple files.You specify multiple definitions or tentative definitions of an identifier.
There are undefined global variables in your code.
The specialization of a template is not in the same file as the template.
The specialization of a template is not in the same file as the definition of the user-defined type for which the template is specialized.
You use a template specialization before declaring it.
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 R2024b1 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.