Skip to main content

IAR Embedded Workbench for RH850 3.20.x

MISRAC++2008-7-3-3 (C++ only)

In this section:
Synopsis

(Required) There shall be no unnamed namespaces in header files.

Enabled by default

Yes

Severity/Certainty

Medium/High

mediumhigh.png
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++2023-10.3.1.

Coding standards
MISRA C++ 2023 10.3.1

(Advisory) There should 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"