Main Content
AUTOSAR C++14 Rule M7-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: Declaration |
Category: Required, Automated |
Version History
Introduced in R2019a