sccn / liblsl

C++ lsl library for multi-modal time-synched data transmission over the local network
Other
108 stars 63 forks source link

`Lambda capture 'this' is not used` warning found when building in Xcode #68

Closed cboulay closed 4 years ago

cboulay commented 4 years ago
async_write(*sock_, lslboost::asio::buffer(serv_->fullinfo_msg_),
            [keepalive, this](err_t, std::size_t) { });

https://github.com/sccn/liblsl/blob/master/src/tcp_server.cpp#L293

Xcode warning - Lambda capture 'this' is not used

Do we not need to handle any errors here?

tstenner commented 4 years ago

The basic technique (as suggested here) is

auto keepalive = shared_from_this();
async_write(*sock_, lslboost::asio::buffer(serv_->fullinfo_msg_),
            [keepalive, this](err_t, std::size_t) { /* shared pointer 'keepalive' is kept alive until the end of this callback */ });

this is also captured so object methods can be called without prefixing keepalive->, but IIRC in this case the lambda function just called an empty method so I removed the call. So, XCode is right and the this can be safely removed.

tstenner commented 4 years ago

I've opened a PR (#69) for it.