Main Content
MISRA C++:2008 Rule 7-3-3
There shall be no unnamed namespaces in header files
Description
Rule Definition
There shall be no unnamed namespaces in header files.
Rationale
According to the C++ standard, names in an unnamed namespace, for instance, aVar
:
namespace { int aVar; }
#include
-s the header file defines its own instance of objects in the namespace. The multiple definitions are probably not what you intended and can lead to unexpected results,
unwanted excess memory usage, or inadvertently violating the one-definition rule.Polyspace Implementation
The checker flags unnamed namespaces in header files.
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: Declarations |
Category: Required |
Version History
Introduced in R2013b