MISRA C++:2008 Rule 7-3-1

The global namespace shall only contain main, namespace declarations and extern "C" declarations

Description

Rule Definition

The global namespace shall only contain main, namespace declarations and extern "C" declarations.

Rationale

The rule makes sure that all names found at global scope are part of a namespace. Adhering to this rule avoids name clashes and ensures that developers do not reuse a variable name, resulting in compilation/linking errors, or shadow a variable name, resulting in possibly unexpected issues later.

Polyspace Implementation

Other than the main function, the checker flags all names used at global scope that are not part of a namespace.

The checker does not flag names at global scope if they are declared in extern "C" blocks (C code included within C++ code). However, if you use the option -no-extern-c, these names are also flagged.

Troubleshooting

If you expect a rule violation but do not see it, refer to the documentation for Polyspace® Bug Finder™ or Polyspace Bug Finder Server™.

Check Information

Group: Declarations
Category: Required
Introduced in R2013b