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.
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: