7

Reading this, I got the impression that this code should work:

class Connection : public std::enable_shared_from_this<Connection>
{
public:
    Connection(tcp::socket&& socket) : socket_(std::move(socket)) {}
private:
    tcp::socket socket_;
};

But the compiler issues this error in the constructor:

Call to implicitly-deleted copy constructor of 'tcp::socket' (aka'basic_stream_socket<boost::asio::ip::tcp>')

I have also defined BOOST_ASIO_HAS_MOVE . I use Xcode 4.6.3 and in the compiler settings I have this defined:

C++ Language dialect: GNU++11[-std=gnu++11]
C++ Standard Library: libc++(LLVM C++ standard library with C++11 support)
8
  • 2
    Could you show the code that calls Connecion constructor? Commented Jul 28, 2013 at 16:23
  • @Igor R: I have another server class which I use it in main(), but the Connection class is not used anywhere. It is just declared Commented Jul 28, 2013 at 16:27
  • 1
    So you are getting an error about calling an implicitly-deleted copy constructor, but no code constructs a Connection object? Does the compiler provide a trace of where the error was instantiated? This problem normal manifest itself when the code calling the constructor passes socket as an rvalue reference, rather than converting it to an xvalue via std::move. Commented Jul 29, 2013 at 13:51
  • This is the highlighted part: std::move(socket). From what I see, the problem is that tcp::socket has a move constructor defined, but no copy constructor so, the implicit copy constructor gets deleted. Commented Jul 29, 2013 at 16:16
  • 1
    please edit your question to include a minimally complete example demonstrating the problem. I cannot reproduce. Commented Jul 29, 2013 at 20:51

1 Answer 1

5

You need to have BOOST_ASIO_HAS_MOVE defined before including the ASIO headers. If you don't, move support is disabled. See asio/basic_stream_socket.hpp.

https://svn.boost.org/trac/boost/ticket/8959

Sign up to request clarification or add additional context in comments.

1 Comment

Explicitly defining BOOST_ASIO_HAS_MOVE didn't work for me. I had to modify /usr/include/boost/asio/detail/config.hpp. I've added // Clang / libc++ detection and replaced // Support move construction and assignment on compilers known to allow it. sections with the ones from: boost.org/doc/libs/1_55_0/boost/asio/detail/config.hpp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.