I have a .h file here that is C code, but looking at the violations reported by Sonar it appears that it is interpreted as C++. For example, the violation “move declaration to a namespace” is reported.
I have a little idea why this happens: we have a “core” code in C and “unit testing” code in C++, both use the same .h file.
Could you confirm if what I’m supposing is true ? What is the behavior of Sonar in such cases ?
Headers are not analysed independently, but as part of a translation unit. So in your case, the header will be analyzed both as C (when included from a C file) and as C++ (when included from a C++ file).
If this is an issue for you, you might want to exclude test code from the analysis? (but it will have the side-effect of… excluding test code from the analysis, therefore maybe hiding real problems in the test code…)