Scanner thinks my .h is C++ code

scanner
sonarcfamily

(dexter) #1

Hi all,

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 ?

Regards


(Loïc Joly) #2

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…)


(Muddsar) #3

i believe you can change your project settings under

Project -> Administration -> General Settings -> C/C++/Objective C

You can edit the file suffixex settings for each language to match with your project needs


(dexter) #4

Thank you.

That’s what we plan to do: test code will never make its way to customer so it seems OK to not scan it.