MISRAC++2023-6.0.3 (C++ only)
In this section:
Synopsis
(Advisory) The only declarations in the global namespace should be main, namespace declarations and extern C declarations
Enabled by default
No
Severity/Certainty
Medium/Medium

Full description
Found a global declaration not being main, namespace or extern C. This check is identical to MISRAC++2008-7-3-1.
Coding standards
- MISRA C++ 2008 7-3-1
(Required) The global namespace shall only contain main, namespace declarations and extern "C" declarations.
Code examples
The following code example fails the check and will give a warning:
void example(){}
The following code example passes the check and will not give a warning about this issue:
namespace {
void example(){}
}