Dear Community,
My team bought SonarQube several months ago, we would like to use it to on a C++ and Qt project. Unfortunately we have some issues with it, and that’s why I ask for your help.
Our problem is, that SonarQube finds very many false positive issues in our code. The cause of most of these issues is, that for some reason SonarQube thinks, that a codeblock is empty. You can see examples on the picture attached.
Some of these issues are seem to have connection with the std library, but only with its functions that are available in the newer C++ standards.
We reproduced this issue on a very simple code example. In this code there are two simple Calculator classes with the same functionality. The first one uses std::optional and produces the above errors (see errors in the picture):
std::optional<int> Calculator::getValue() const
{
if (*m_value == 0)
{
return std::nullopt;
}
return m_value;
}
void Calculator::addValue(int value)
{
m_value = *m_value + value;
}
The second one doesn’t use std::optional and doesn’t produce any such errors:
int Calculator2::getValue() const
{
if (m_value == 0)
{
return 0;
}
return m_value;
}
void Calculator2::addValue(int value)
{
m_value = m_value + value;
}
The scanning was done with the following commands:
build-wrapper-win-x86-64.exe --out-dir bw_output MSBuild.exe SonarQubeTest.sln /p:Platform=x86 /t:Rebuild /m
sonar-scanner.bat -Dsonar.projectKey=SonarQubeTest -Dsonar.sources=. -Dsonar.host.url=http://localhost:9000 -Dsonar.login=1c98bc23b07ad4bdb0a6b1236cc1fe0de62950b3
We also tried this command:
sonar-scanner.bat -Dsonar.projectKey=SonarQubeTest -Dsonar.sources=. -Dsonar.language=cpp -Dsonar.cpp.std=c++17 -Dsonar.host.url=http://localhost:9000 -Dsonar.login=1c98bc23b07ad4bdb0a6b1236cc1fe0de62950b3
Could you please help us with this issue? Is there anything we should do differently?
Out SonarQube version: 7.6
Sonar-Scanner version: 3.3.0.1492
Thank you for any help!