MISRAC++2023-10.3.1 (C++ only)
In this section:
Synopsis
(Advisory) There should be no unnamed namespaces in header files
Enabled by default
No
Severity/Certainty
Medium/High

Full description
Any entity declared in an anonymous namespace in a header file will be different in different translation units which may be unexpected. This check is identical to MISRAC++2008-7-3-3.
Coding standards
- MISRA C++ 2008 7-3-3
(Required) There shall be no unnamed namespaces in header files.
Code examples
The following code example fails the check and will give a warning:
// header.h contents:
// namespace {
// int x = 0;
// }
#include "header.h"
The following code example passes the check and will not give a warning about this issue:
// header_x.h contents:
// namespace X {
// int x = 0;
// }
#include "header_x.h"