Main Content
MISRA C++:2023 Rule 10.3.1
Description
Rule Definition
There should 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: Advisory |
Version History
Introduced in R2024b