cpp:SingleDeclarationPerStatement: possible false positive when writing members of a class

Hi, I’m using the SonarLint plugin version 6.0.0.37696 in CLion and have to report a possible false positive in this class:

#ifndef RUBRICA_CONTACT_H
#define RUBRICA_CONTACT_H

#include <string>
#include <regex>

class Contact {
public:
    const std::regex numberPattern{R"(([+][\d]{2,3})?[\s]*[\d]{10})"};
    Contact(std::string_view name, std::string_view number);

private:
    std::string name;
    std::string number;   // <---- This is the line that raises the issue
};

#endif //RUBRICA_CONTACT_H

The issue raised is cpp:SingleDeclarationPerStatement, at the line declaring the number variable. As you can see, there’s no such multiple declaration anywhere in the code.
I also want to underline that I have always declared my member variables this way, and never had any problems nor raised any issue.

Hello @Thomas_Herondale,

This is the same issue as the previous one.
Due to the same bug, we aren’t able to find standard header files with MSVC which leads to a lot of false positives. In your case with std::string. This bug has the potential of impacting the behavior of every rule.

As a workaround until the fix is shipped you can try to temporarily explicitly add the Microsoft standard include to your project.

For example, adding this to my CMake made the false-positive disappear:

include_directories(
SYSTEM
“C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\ATLMFC\include”
“C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include”
“C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um”
“C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt”
“C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared”
“C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um”
“C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt”
“C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt”
)

You should be able to find your system include by checking the Microsoft INCLUDE environment variable.

Note: you will have to reload the CMake for the new configuration to take effect.

Thank you for the answer, and sorry for bothering with the same exact error, couldn’t imagine this could affect so many different issues.
Thank you.

@Thomas_Herondale,

No worries, it is not obvious at all. Please confirm if the workaround fixes the false positives.

Thanks,

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

Hello @Thomas_Herondale,

The fix was released. it should fix reported false positives and make the analysis more accurate.

Thanks,