False positive on .h in "extern C" block being analyzed as C++ code

On a SonarQube Developper v2026.1 solution deployed through the official helm chart, I’m getting a false positive on C++ rule Scoped enumerations should be used in .h code wrapped into extern "C" block.

I understand the code is analyzed as C++ code because this header is also imported in tests written in C++. But I would expect a block of C code wrapped in an extern "C" block to not be analyzed through C++ rules.

I tried to fix the C/C++/Objective-C file extensions through Administration / General Settings / Languages configuration but it did not help, .h is already assigned to C. I did the same with environment variables added to sonar-scanner:

-Dsonar.lang.patterns.c=**/*.h,**/*.c \
-Dsonar.lang.patterns.cpp=**/*.hpp,**/*.cpp
-Dsonar.c.file.suffixes=.c,.h \
-Dsonar.cpp.file.suffixes=.cpp,.hpp

But it did not help either.

...
#ifdef __cplusplus
extern "C" {
#endif

typedef enum _COOK_RecpPowerDCBiasState_E
{
	COOK_DC_BIAS_STATE_WAIT_FOR_FILTER_STABLE = 0,
	COOK_DC_BIAS_STATE_INIT_OUTPUT = 1,
	COOK_DC_BIAS_STATE_CONFIGURE_REGULATOR = 2,
	COOK_DC_BIAS_STATE_REGULATOR_RUNNIONG = 3,
}COOK_RecpPowerDCBiasState_E;

...

#ifdef __cplusplus
}   // extern "C"
#endif

Hi @oboucom,

It is true that currently, the language used to analyze a header is the one of the file that includes it. So if the header is included both from C and from C++ code, it means that when included from C++, it will be considered as C++, no matter what, and the issue will be raised.

There are case where it makes sense, because code wrapped in extern "C" might still be C++ code.

We are currently considering a workaround for this, where we would detect files included from both languages, and in that case filter-out all C++-only violations. Would it work in your situation, or is this C header only included from C++ files in your analysis?

Hi Loïc,

The code is included in both C test (the main code), and C++ (tests). So what you propose would fix the issue. We can’t adjust the header otherwise it would break the C code that includes it.

Thanks,

Olivier.