This is regarding MISRA rule 16-0-2 from MISRA C++ 2008 guidelines
Macros shall only be #define'd or #undef'd in the global namespace.
I understand this rule but my polyspace misra checking tool complains that following include guard declared at the beginning of file as Non-Compliant. I guess this can happen if this file itself is included in another namespace, but this is not the case with my header file.
What other mistakes in code may cause this issue?
#ifndef FOO_H
#define FOO_H
... code etc ...
#endif
Note : Example quoted in Misra guidelines is
#ifndef MY_HDR
#define MY_HDR // Compliant
namespace NS
{
#define FOO // Non- Compliant
#undef FOO // Non-Compliant
}
#endif
If those header guards are placed outside any braces (in the global namespace), then your code is fine and your tool is broken. Send a bug report to Polyspace.
The rationale behind this rule is that pre-processor directives shouldn't be placed inside braces (inside namespace declarations or functions etc) because their scope is always global no matter where they are placed.