How can I remove annoying warning "non-void function does not return a value in all control paths"?
There are some explanation of my code:
- Poll two sockets.
- a) If there any data on transport socket -> recv and return message from function
b) If there any data on inproc socket -> recv and forward message from inproc socket to transport socket and continue to poll.
std::optional<std::pair<std::string, std::string> > pizza::transport::SharedAsyncPoller::receive() { // poll both sockets and return if there while (m_poller.poll()) { // if any data appears on transport socket if (m_poller.has_input(m_transportSocket)) { zmqpp::message msg; m_transportSocket.receive(msg); if (msg.parts() < 2) return std::nullopt; else return std::make_pair(msg.get(0), msg.get(1)); } // or if there any data on inproc socket if (m_poller.has_input(m_inprocSocket)) { zmqpp::message msg; m_inprocSocket.receive(msg); m_transportSocket.send(msg); // it is okay that we do not return anything // we just forward the message from inproc to transport socket // and continue to poll sockets } } }
return std::nulloptafter that while loop.throwin the unreachable function end. It suppresses warnings too.m_poller.poll()is false? Add that return statement, and program is fixed.