[SERVER-8894] Invalid noncopyable logic in MongoDB C++ client (src/mongo/util/goodies.h) Created: 07/Mar/13  Updated: 23/Nov/16  Resolved: 23/Nov/16

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: 2.4.0-rc2
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Hillel Lubman Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux / g++


Operating System: Linux
Steps To Reproduce:

Compile with g++ against C++ client library with -Wextra flag.

Participants:

 Description   

I get this warning when compiling against MongoDB C++ client library:

...mongo/util/goodies.h:136: warning: base class ‘class boost::noncopyable_::noncopyable’ should be explicitly initialized in the copy constructor

src/mongo/util/goodies.h has the following code:

class ThreadSafeString : boost::noncopyable {
public:
ThreadSafeString( size_t size=256 )
: _size( size ) , _buf( new char[size] )

{ memset( _buf , 0 , _size ); }

ThreadSafeString( const ThreadSafeString& other )
: _size( other._size ) , _buf( new char[_size] )

{ strncpy( _buf , other._buf , _size ); }

What is the point first deriving from private boost::noncopyable and then defining a copy constructor with a body? It defeats the purpose. Either it could just define a private copy constructor, or define none at all and privately derive from boost::noncopyable.
Either way it would avoid this warning.



 Comments   
Comment by Eric Milkie [ 23/Nov/16 ]

ThreadSafeString no longer inherits from boost::noncopyable; the class is made noncopyable via a different method.

Comment by Hillel Lubman [ 13/Mar/13 ]

The logic is also quite misleading, since defining a copy constructor renders deriving from boost::noncopyable useless. I.e. you can copy ThreadSafeString and nothing will prevent it.

So what was the intention? To make it noncopyable or not?

Generated at Thu Feb 08 03:18:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.