Header file contains unnamed namespace leading to multiple definitions
This defect occurs when an unnamed namespace is used in a header file, which can lead to multiple definitions of objects in the namespace.
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.Specify names for namespaces in header files or avoid using namespaces in header files.
| Group: Programming |
| Language: C++ |
| Default: On for handwritten code, off for generated code |
Command-Line Syntax:
UNNAMED_NAMESPACE_IN_HEADER |
| Impact: Medium |