Mixed C/C++ Project: SonarLint applying C++ rules to C headers

Hi @joanpereyra,

I assume you are using Visual Studio in solution mode.
While exclusion/inclusion is synchronized from the server, the language of a header file is detected from the vcxproj setting. Here is an explanation of how to change it to C: C project parsed with C++ rules - #3 by Abbas

This allows you to force the language of header files per vcxproj.

Side note:

  • I don’t think having two projects on SonarQube is ideal. If the analysis is triggering a C++ issue on a .h file, it means the .h file was included in a source file compiled as C++ according to the build-wrapper JSON.

  • If this is the case, and you still want to keep this file C compliant, I expect that you wrap the code with extern C in case __cplusplus.

  • Since the post, we improved our C++ rules to not trigger in extern C context. If they did when you analyzed your codebase in one project, I invite you to post the rules that were triggered on this forum and we will treat them as false-positive and fix them.

3 Likes