- What language is this for?
C++ - Which rule?
cppcheck:passedByValue - Why do you believe it’s a false-positive/false-negative?
std::move should be more efficient than passing by const reference as suggested - Are you using
- SonarCloud?
- SonarQube - which version?
SonarQube 9.9 - SonarLint - which IDE/version?
- in connected mode with SonarQube or SonarCloud?
- How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
#include <string> // Include the <string> header for std::string
class CheckActionAggregator
{
public:
// Constructor with a string parameter
explicit CheckActionAggregator(std::string pName)
: mName(std::move(pName)) // Initialize mName using std::move
{
// No additional code here
}
// Add any other member functions or variables as needed
private:
std::string mName;
// You might want to declare mLogger here if it's a member of CheckActionAggregator
};
int main()
{
// Create an instance of CheckActionAggregator with a name
CheckActionAggregator myAggregator("My Check Action");
// You can now use myAggregator as needed
return 0;
}
The rule will be triggered on the constructor even though there is the std::move which is more efficient than passing by const reference
I found the same false positive in cppcheck
https://trac.cppcheck.net/ticket/8570
Can you confirm it’s a false positive?
Thanks