Main Content

AUTOSAR C++14 Rule M7-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 Ignore link errors (-no-extern-c), these names are also flagged.

Troubleshooting

If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Check Information

Group: Declaration
Category: Required, Automated

Version History

Introduced in R2019a