Use of undeclared in header files

Please provide

  • Operating system: macOS
  • SonarQube for IntelliJ plugin version: 10.16.1.80464
  • IntelliJ version: 2024.3.2
  • Programming language you’re coding in: C++
  • Is connected mode used:
    • SonarQube Server

And a thorough description of the problem / question:

I use CLion with SonarQube for IDE and SonarQube server.
The Sonar scanner see valid errors in CPP files, thats great, but show lots of false error in header files

I use CMAKE and PCH header, so the header files doesn’t includes any other files
example code:

header.h.pch

struct myStruct {};

#include <stdio.h>
#include <stdlib.h>

#include "myheader.h"

myheader.h

struct otherStruct : public myStruct {};

myclass.cpp

#include "header.h"

int main() {
    otherStruct s;

    return 0;
}

Sonar scanner scanning the files and says:
myheader.h:
use of undeclared identifier ‘myStruct’

What can I set to see the precompiled header and the types which comes from other headers?

Hello @Endre_Vass,

Can you please clarify the following for me:

  • Was the analysis run on SonarQube For IDE plugin for CLion or on SonarQube Server via sonar-scanner?
  • Are the false positive issues appearing on SonarQube For IDE or on SonarQube Server?

Thanks,

Hello

I made the connection between CLion and SonarQube server, but the analysis run in the CLion (on the sonar server I didn’t see these errors, so that is works fine)

These errors shows in the CLion, on the server everything is fine

Hello,

Thank you for clarifying the situation. In order to investigate this issue, Can you generate a reproducer file and share it with us by adding the following analysis property sonar.cfamily.reproducer=PATH_OF_FILE_TO_ANALYZE. and running the analysis on your file of interest.

In the log, you should see that a file is generated. Please send it to us. If you think this file contains private information, let us know, we’ll send you a private message that will allow you to send it privately.

Thanks,

I added to the properties:
[sonarlint-analysis-engine] INFO sonarlint - sonar.cfamily.reproducer=/Users/myuser/sonar.analysis

Run the analysis, but the file didn’t created …
And the analysis didn’t works :frowning: I add an error to the file, but:
[sonarlint-analysis-engine] INFO sonarlint - Analysis detected 0 issues and 0 Security Hotspots in 101ms

I run a full project check, and no file generated, no issue found but that is not true :frowning:
If I remove this option, show lots of false positive error :frowning:

Hello @Endre_Vass,

In order to better understand the situation, Can you share the verbose logs of the analysis?, You can do that by following these steps:

  • Make sure to enable analysis logs and verbose
  • Clear the logs
  • Make sure you have the sonar.cfamily.reproducer=/path/of/file/to/analyze.cpp set in your analysis properties
  • Run analysis for the file of interest, which should be the same file provided in the sonar.cfamily.reproducer analysis property, namely /path/of/file/to/analyze.cpp
  • Share the full SonarQube for IDE logs with us, If you believe the logs might contain sensitive data, and You prefer to share them privately, please let me know, I can start a private thread with you

Thanks