PPIncludeNotAtTop triggers inside extern "C" block

Using SonarQube version 8.9.1

There is this rule called cpp:PPIncludeNotAtTop which appears to be listed here Rules explorer

This rule appears to be missing an exception for blocks like extern "C"

extern "C" {
#include "some_h_file.h
}

Which means this code smell is triggered by the construction itself where C++ files contain include directives that a are placed inside an extern "C" block. I guess the same goes for the corresponding extern "C++" in C code.

I’m pretty sure this construct is needed for my case, because we link with object files that are compiled from C code by a C compiler.

I guess on a theoretical basis, we could possibly compile the C code with the C++ compiler if these files are written using only parts of C that also are valid C++. However, in general, C is not a subset of C++, therefore there will be cases where this is not possible.

I hope this use case is considered as important enough to either change the existing rule, add a configuration or a separate rule for.

Hi @torgeir.skogen ,

thank you for your report, it has been recently fixed in CPP-3143 and it is going to be available soon on SonarCloud or in SonaQube 9.1.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.