Main Content
Unnamed namespace in header file
Header file contains unnamed namespace leading to multiple definitions
Description
This defect occurs when an unnamed namespace is used in a header file, which can lead to multiple definitions of objects in the namespace.
Risk
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.Fix
Specify names for namespaces in header files or avoid using namespaces in header files.
Examples
Result Information
Group: Programming |
Language: C++ |
Default: On for handwritten code, off for generated code |
Command-Line Syntax:
UNNAMED_NAMESPACE_IN_HEADER |
Impact: Medium |
Version History
Introduced in R2019b
See Also
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)