False positives in SonarLint C++ rules in C header files in CLion

We are having false positives with .h files because they are considered C++ by Sonarlint while they are C files. They produce a lot of these issues:

  1. Macros should not be used to define constants
  2. “using” should be preferred for type aliasing
  3. Scoped enumerations should be used

We have connected to a Sonarqube instance which defines the file types associated with languages and .h files are only supposed to be considered as C, but they are clearly not when coding in the IDE. The scan works fine when done only with sonar-scanner.

How can we tell CLion and/or Sonarlint that these are C files and not C++?

Thank you

Hi @GlassOfWater69 ,

could you try to open the .h file on your editor and launch the Show Compiler Info action and share its output?

Hey @mpaladin ,

Here it is. I can clearly see that CLion parses this .h file as CPP, but that’s not the behaviour I want. Is it possible to change that behaviour?

Compiler info for 'Com.h' in configuration 'Com | Coverage Ninja' for language CPP

Compiler kind: null path: null

Compiler switches:

null

Compiler info:

Defines:

Features:


Implicit includes:


Header Search paths:

Hi @GlassOfWater69 ,

we use the configuration given by CLion to analyze the source file, it seems like your project is not well configured in CLion. Is it a CMake project? Did you reload the project?

Hi @mpaladin,

The Com.h file is in a mixed language project using C and C++ with CMake. I want to analyse .h files in this project as C and not C++. Are you aware of a way in CLion to parse .h files as C and not C++?

Hi @GlassOfWater69 ,

if you have a build configuration using such .h file as C you can select it in the top-right “Active configuration” drop-down menu, which should change the configuration used to analyze the file.