An unnamed namespace will be unique within each translation unit. Any declarations appearing in an unnamed namespace in a header will refer to a
different entity in each translation unit, which is probably not the expected behavior.
Noncompliant code example
// Header.hpp
namespace // Noncompliant
{
extern int32_t x;
}
// File1.cpp
#include "Header.hpp"
namespace
{
int32_t x;
}
void fn_a(void)
{
x = 42;
}
// File2.cpp
#include "Header.hpp"
namespace
{
int32_t x; // this is a different x than in File1.cpp
}
void fn_b(void)
{
fn_a(); // Is expected to initialize "x" to 42
if (x == 42) // But does not, as there are 2 distinct "x" variables
{
}
}