AutosarC++18_03-M7.3.3¶
There shall be no unnamed namespaces in header files
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
An unnamed namespace will be unique within each translation unit. Any declarations appearing in an unnamed namespace in a header will refer to different entities in each translation unit, which may not be consistent with developer expectations.
Example
// Header.hpp
namespace // Non-compliant
{
extern int32_t x;
}
// file1.cpp
#include "Header.hpp"
namespace
{
int32_t x;
}
void fn_a ( void )
{
x = 24;
}
// file2.cpp
#include "Header.hpp"
namespace
{
int32_t x;
}
void fn_b ( void )
{
fn_a ( );
if ( x == 24 ) // This x will not have been initialized.
{
}
}
Note
For legal reasons, this rule’s description is not part of the public documentation.