避免使用c++编译器的正确方法是什么;s警告



如何删除烦人的警告"非void函数不返回所有控制路径中的值";?

我的代码有一些解释:

  1. 轮询两个套接字
  2. a( 如果在传输套接字上有任何数据->recv并从函数返回消息
    b(如果inproc套接字上有任何数据->recv并将消息从inproc套接字转发到传输套接字并继续轮询
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
}
}
}

从代码来看,警告是合法的。

m_poller.poll()返回false时,函数到达非void函数的末尾而不返回。

因此,您必须在循环后使用return(或throw,或将无返回函数调用为abort(。

如果CCD_ 6不能返回false(由于隐藏的依赖性(,你可以重写你的循环(从而避免不必要的条件(

while (true) {
m_poller.poll();
// ...
}

相关内容

最新更新