"Explicitly define the missing copy assignment operator so that it will not be implicitly provided" rule fails for a class derived from boost::noncopyable

I have a class like this:

class MockServer : public boost::noncopyable
{
public:
	void Run();
	~MockServer();
private:
	listener_t m_listener;
};

Since it derives from boost::noncopyable (noncopyable - 1.63.0), the implicit copy assignment operator won’t be generated. Still SonarQube reports this as an error. In my eyes using boost::noncopyable (or similar classes) is easier than explicitly delete copy assignment operator (and the others) and has the same effect on code correctness.

The destructor is needed to close the listener.

Using SonarQube, Version 8.3.1 (build 34397). C++.

Hello @Vojtech_Fried,

Welcome to the community and I apologize for the late reply.

I tried your case and it seems to be working when inheriting from noncopyable. Only when I remove the inheritance the issue is raised. This makes me guess that the issue might be in the configuration and not in the rule.

To move forward l suggest this:

  • Check if the issue still exists on the latest version
  • If yes, please share with me the log of the scanner in debug mode.
  • Please generate a reproducer for the file that contains the false positive.

To generate a reproducer file:

  • Add the reproducer option to the scanner configuration:
    sonar.cfamily.reproducer= "Full path to the .cpp file that has or include the file that has the false-positive"
  • Re-running the scanner should generate a file named sonar-cfamily.reproducer in the project folder.
  • Please share this file. if you think this file contains private information we can send it privately.

Thanks,

Our SQ is deployed by the company. I can’t try a new version of it. Is there any online test where I could give it a try?
Is it possible to try SQ locally (Visual Sudio 2019 addon) to at least isolate the problem?
Or if anyone want to try, listener_t is
typedef web::http::experimental::listener::http_listener listener_t;
from GitHub - microsoft/cpprestsdk: The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
This is how its declaration would look like:
class http_listener
{
public:
http_listener(http::uri address);
http_listener(http::uri address, http_listener_config config);
http_listener();
~http_listener();
pplx::task open();
pplx::task close();
void support(const std::function<void(http_request)>& handler);
void support(const http::method& method, const std::function<void(http_request)>& handler);
const http::uri& uri() const;
const http_listener_config& configuration() const;
http_listener(http_listener&& other);
http_listener& operator=(http_listener&& other);
private:
// No copying of listeners.
http_listener(const http_listener& other);
http_listener& operator=(const http_listener& other);
//
std::unique_ptr< details::http_listener_impl > m_impl;
};

@Vojtech_Fried You can use SonarLint plugin for visual studio(it is a free extension). It has the same rules so you can isolate the example there and share it(You can automatically generate a reproducer file for SonarLint too).

The reproducer is meant to generate an example to reproduce your case and you don’t need an update SQ to generate it.

Thanks,