cpp:S1003 - False Using Directives flagged in .cpp file

Hi all,

I continually get false positives for using namespace directives within .cpp files. As I understand and the rule description states, it is only valid for .h and .cc files, not for .cpp

This is using SonarQube for VSCode (connected mode), and the problems are NOT flagged in SonarCloud, only in the IDE while writing code.

Minimal reproduction:

test.h

namespace foo {}

test.cpp

#include "test.h"
using namespace foo;

Hi @Attempt3035 and thanks for sharing the issue with us,

I wasn’t able to reproduce the issue with the minimal example you shared, but I think that identifying a file as a header file in your project depends on the content of the compilation database (not on the file extension).

To help us identify the cause, would it be possible for you to share the following:

  • The full SonarQube for IDE logs. You can retrieve them using the instructions in this section in the docs.
  • Your compilation database file and information on how you are generating it.
  • The name of the .cpp file where you are observing the false positives.

I can also start a private thread with you if you prefer not to share this information publicly.

Best regards,
Michael

Hi Michael,

The compilation database is being generated using my fork of Hedronvision’s Bazel Compile Commands tool, my fork having a minor change to solve this issue described Here

The name of the .cpp file from the example was test.cpp, but it seems to occur with any file names in some of my larger projects.

If you’re able to start a private thread that would be great, I’ll share the compilation database & logs there.

Thanks so much,
Luke

Hi @Attempt3035,

I started a private thread, let me know if you encounter problems sharing the files.