QtCreator语义问题警告代码永远不会被执行

时间:2016-07-27 06:54:39

标签: qt qt-creator

我有以下Qt代码块:

if(this->ueCommunicationsSocket()->bind(QHostAddress(data[0].toString()),
                                        static_cast<quint16>(data[1].toInt())),
                                        QAbstractSocket::ShareAddress)
{
    qDebug() << Q_FUNC_INFO
             << "TCP socket bind succesfull";
}
else
{
    qDebug() << Q_FUNC_INFO
             << QString::number(this->ueCommunicationsSocket()->error())
             << this->ueCommunicationsSocket()->errorString();  // here i get semantic issue
}   // if

我的语义问题警告代码永远不会被执行。我知道这是一个愚蠢的错误,我准备好了,但是,我找不到错误!这是一个截图: Qt Creator Semantic Issue

1 个答案:

答案 0 :(得分:2)

if(this->ueCommunicationsSocket()->bind(QHostAddress(data[0].toString()),
                                        static_cast<quint16>(data[1].toInt())),
                                        QAbstractSocket::ShareAddress)

if ( /*something */, QAbstractSocket::ShareAddress) 

由于AbstractSocket::SharedAddress0x1,因此带有逗号运算符! 的条件始终为真,即永远不会执行else分支。