codeql-coding-standards
codeql-coding-standards copied to clipboard
`A2-10-1`: Report type and function identifier hiding
Affected rules
-
A2-10-1
Description
A2-10-1
states "An identifier declared in an inner scope shall not hide an identifier declared in an outer scope.". The existing query looks for user defined variables which cause hiding, but functions and types can also be hidden (and cause hiding).
Example
int a;
namespace b {
void a() { } // NON_COMPLIANT
int c() { return a; }
}
This is an interesting example that is close to the exception discussed in Autosar, but still marked as non-compliant in the examples in Autosar. It is interesting because like the exception we can still reference a
in the global scope as:
int a;
namespace b {
void a() { }
int c() { return ::a; }
}
It seems MISRA C++ 23 completely removes the exceptions in 6.5.1. The also only focus on variables (6.4.1) and member functions (6.4.2)
It is interesting to have the distinction between global namespace and named namespace for the exception since both cases the hidden variable can still be referenced, but in one case it is accepted and the other not. Seems equally confusing as is confirmed by MISRA C++ 23.